Tried many solutions, but cannot use the setOnItemClickListener() in the example given in the following link http://www.brightec.co.uk/ideas/android-listview-alphabet-scroller
答案 0 :(得分:1)
Try the following:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
答案 1 :(得分:1)
this is how i got my setOnItemClickListener working:
private ListView myList;
myList= (ListView) findViewById(R.id.myList);
myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// DO SOME ACTION
}
});
答案 2 :(得分:0)
You need to directly override the method onListItemClick()
since the link you given is extending the ListActivity
You should have a look on the docs-
The Super class ListActivity is having the protected
method~-
/**
* This method will be called when an item in the list is selected.
* Subclasses should override. Subclasses can call
* getListView().getItemAtPosition(position) if they need to access the
* data associated with the selected item.
*
* @param l The ListView where the click happened
* @param v The view that was clicked within the ListView
* @param position The position of the view in the list
* @param id The row id of the item that was clicked
*/
protected void onListItemClick(ListView l, View v, int position, long id) {
}
答案 3 :(得分:0)
当您使用onListItemClick()方法时,在ListView的xml文件中,您必须将此id提供给ListView:
@android:ID /列表