我有一個具有SimpleCursorAdapter的應用程序。我可以將數據庫表的內容顯示在列表中,但我想在點擊列表中的項目時執行某些操作。當我去eclipse中源代碼並嘗試重寫一個clickListener時,沒有什麼可以重載。我正在尋找一個像OnListitemClick一樣覆蓋的方法。我會怎麼做?如何覆蓋onListitemClick
Eclipse也抱怨方法onListItemClick,sayimg它必須重寫或實現一個超類型方法。如果我刪除了@Override註解,然後錯誤發生,列表顯示,但沒有觸發列表中的項目觸發事件。
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");
}
嘿謝謝,作品一種享受! – turtleboy