Button on listView
i have 开发者_如何学JAVAa button in listview .now i want to use button.setonclicklistener and onListItemClick what i need to do
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); }
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.)
精彩评论