How to access UI elements created by a List Adapter from an Activity?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 23:05:10

问题


In my code now, I have a DetailActivity, which simply calls a ListAdapter class to populate a ListView.

Within the ListAdapter class, I am inflating some custom views, some of which contain Buttons.

Back from within my DetailActivity, I would like to be able to access these buttons to enable/disable them depending on certain user actions. Is there a way to do this?

I guess the larger question is: from an Activity, how can I grab a reference to any element (buttons, imageviews, textviews,etc) that are created from an Adapter?

Thank you!


回答1:


I assume you have a List<Object> that is sent through the constructor of ListAdapter. Just add a boolean isEnable to the Object, and then in your getView() method, add this line:

button.setEnabled(getItem(position).isEnable);

In your DetailActivity, you can changeisEnable as you wish. And remember to adapter.notifyDataSetChanged() to get it worked.



来源:https://stackoverflow.com/questions/16370426/how-to-access-ui-elements-created-by-a-list-adapter-from-an-activity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!