i have a button in listview .now i want to use button.setonclicklistener and onListItemClick what i need to do
2 Answers
For handling events of ListActivity the first thing you need is
getListView() This method returns the embedded ListView of the Activity.
For setting the listener, you have to put the following code in OnCreate(Bundle BundleSavedInstanceState) method :
getListView().setOnItemClickListener(this);
And implement the click handler: public void onItemClick(AdapterView parent, View view, int position, long id) { // TODO Auto-generated method stub ArrayAdapter adapter = (ArrayAdapter) parent.getAdapter(); adapter.getItem(position); }

- 259
- 2
- 6
You can call setItemsCanFocus(true)
on your ListView and set your buttons' focusable and clickable property to true;
Heres a sample code:
if your using using a ListAcitivity to display your list items:
you can call:
getListView.setItemsCanFocus(true);
button.setFocusable(true);
button.setClickable(true);
optionally you can define those clickable properties of button from XML file (if you are inflating an xml based layout in your custom adapter.)

- 27,760
- 6
- 37
- 35
-
setItemsCanFocus makes some significant changes in how ListView handles interaction. The short answer is that you don't want to try using an item click listener when you're in this mode. See this question for more info about this: http://stackoverflow.com/questions/3789943/using-android-how-can-i-select-rows-from-a-listview-which-contains-button-contro/3791340#3791340 – adamp Nov 21 '10 at 19:02