0

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!

kurisukun
  • 3,149
  • 5
  • 37
  • 69

1 Answers1

2

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.

Aprian
  • 1,718
  • 1
  • 14
  • 24