问题
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