I have an app that has a SimpleCursorAdapter. I can get the content of the DB table to show up in the list but i’d like to do something when the item in the list is clicked. When i go to source in eclipse and try to override a clickListener there is nothing to override. I’m looking for a method to override like onListitemClick. How would i do ths?
Eclipse is also complain about the method onListItemClick, sayimg that it must override or implement a supertype method. If i delete the @Override annotation then that error goes, the list is displayed but no event is fired from touching an item in the list.
private class MyAdapter extends SimpleCursorAdapter {
public MyAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
}
@Override
public
View getView(int position, View convertView, ViewGroup parent) {
Log.e(TAG, "inside myadapter getview");
View v = super.getView(position, convertView, parent);
if(v == null)
return null;
Cursor c = (Cursor)getItem(position);
String phoneName = c.getString(c.getColumnIndex(LoginValidate.C_PHONE_NAME));
String phoneNumber = c.getString(c.getColumnIndex(LoginValidate.C_PHONE_NUMBER));
((TextView)v.findViewById(R.id.phonename)).setText(phoneName );
((TextView)v.findViewById(R.id.phonenumber)).setText(phoneNumber);
((TextView)v.findViewById(R.id.phonename)).setTextColor(Color.BLACK);
((TextView)v.findViewById(R.id.phonenumber)).setTextColor(Color.BLACK);
return v;
}
}// end of adapter
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Log.e(TAG, "clicked an item in list");
}
The adapter doesn’t have an onListItemClick() method by default, which is why the annotation is bothering it.
You have to tie in the onListItemClick() to the listView… try using it by
or just like this
and that should do it.
To sum up:
1) either implement the correct interface in your adapter and it will require the override annotation
2) leave the method exposed in the adapter and call it from a private onListItemClickListener attached to the listview.