问题
I have listed a list with custom adapter to display different images in each list item and succeeded. Now i need to add a onitemclick listener for that list. Unable to access the id because the list id is - "@+id/android:list". Unable to identify this id.
Any ideas please share. You will get some more idea when you see this below link
Click here for the example i tried.
回答1:
In the given example, the ListActivity is extended in CustomAdapterActivity.java
so its simple to get Click events of the list items by writing list item click listener
and to write onClickListener you need to do
like this in that class.
**
public class Test extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ListView lv = getListView();
lv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
}
**
And To Know More and Learn About LIST VIEW in Android you can view this : http://www.vogella.de/articles/AndroidListView/article.html#overview_listview
来源:https://stackoverflow.com/questions/7753765/can-i-get-onclicklistener-for-this-list-listed-by-customadapter