Access View From Another Layout
I'm using a ListView with custom list items (including a button). I have a custom adapter, in which I set the button's OnClickListener to an inner class (defined in the adapter cla
Solution 1:
Easy way to achieve this is to create a field inside your CustomAdapter
class:
private OnClickListener listener;
Then specify a setter method for this field. Next step will be to specify this listener inside your Activity
class like that:
CustomAdapteradapter= (CustomAdapter) getListView().getAdapter();
adapter.setListener(<your implementation of the listener>);
Then inside your CustomAdapter
's getView()
method you set this listener to your button:
Buttonbtn= (Button) convertView.findViewById(R.id.btn);
btn.setOnClickListener(listener);
Hope this helps.
Post a Comment for "Access View From Another Layout"