我在我的應用程序下面的代碼:的ListView不聽OnClickListener
AnotherCursorAdapter adapter = new AnotherCursorAdapter(CadItemActivity.this,
R.layout.imgsinternas,
cursorImagens,
new String[] {"nome", "tags",},
new int[] { R.id.txtNome, R.id.txtTags });
telaScroll.setAdapter(adapter);
telaScroll.setClickable(true);
telaScroll.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
Log.d("1212121", "OnClick");
// return false;
}
});
代碼AnotherCursorAdapter:
public class AnotherCursorAdapter extends SimpleCursorAdapter {
private LayoutInflater inflater;
public AnotherCursorAdapter(Context context,
int layout,
Cursor c,
String[] from,
int[] to) {
super(context, layout, c, from, to);
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// get the views from the row
TextView name = (TextView) view.findViewById(R.id.txtNome);
TextView tags = (TextView) view.findViewById(R.id.txtTags);
ImageView img = (ImageView) view.findViewById(R.id.figura);
//asign the values
name.setText(cursor.getString(4));
tags.setText(cursor.getString(3));
name.setClickable(true);
tags.setClickable(true);
img.setClickable(true);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = inflater.inflate(R.layout.imgsinternas, null);
return v;
}
}
telaScroll是我的數據庫填充一個ListView。我沒有從ListActivity擴展。
上面的代碼不工作!
事件沒有被觸發!
我在做什麼錯? =(
您是否使用自定義適配器?你的名單有什麼看法。即你的列表是否帶有點擊監聽器的按鈕? – Jayabal 2012-03-12 04:47:43
你好巴亞!謝謝回答。我使用的是自定義適配器,而我的listview是一個包含imageview和文本的列表。他們充氣。我將它們設置爲android:clickable =「true」,但它沒有幫助。我想單擊圖像(也許也是textview)並獲取他們的信息。你能幫我嗎? – 2012-03-12 04:53:22
可以粘貼更多的代碼,我可以看到這是什麼問題 – Khan 2012-03-12 04:57:10