所以我有一个我用于listview的CursorAdapter。我希望每个列表项都有4个可点击的视图,因为当点击每个东西时我会发生不同的事情......这里不重要。
我的问题...... 是我无法同时获取所选项目(或行)中的数据以及在该列表项目中单击的视图(1到4)。
到目前为止我尝试了什么:
也许这些策略中的一个是正确的,我不是要么以正确的方式获取数据,要么正确地获取视图。无论如何,任何帮助将不胜感激!
从我的CursorAdapter实现onClick时:
@Override
public void bindView(View v, Context context, Cursor c) {
ImageView imPlay = (ImageView) v.findViewById(R.id.row_play_button);
LinearLayout llFirstHalf = (LinearLayout) v.findViewById(R.id.row_first_half);
LinearLayout llSecondHalf = (LinearLayout) v.findViewById(R.id.row_second_half);
CheckBox cbCheck = (CheckBox) v.findViewById(R.id.row_checkbox);
}
public void myOnClick(View v) {
switch(v.getId()){
case R.id.row_checkbox:
//do something
break;
case R.id.row_first_half:
//do something
break;
case R.id.row_second_half:
//do something
break;
case R.id.row_play_button:
//do something
break;
在MainActivity中实现onItemClick时:
@Override
public void onItemClick(AdapterView<?> parent, View view, int index, long pos) {
Log.e("onITEMCLICK", "index: "+String.valueOf(index));
Log.e("onITEMCLICK", "position: "+String.valueOf(pos));
LinearLayout listItem = (LinearLayout) view;
String title;
String date_created;
String comments;
String sample_rate;
String duration;
String file_size;
String id;
String file_url;
Cursor c = app.rec_adapter.getCursor();
c.moveToPosition(index);
title = c.getString(c.getColumnIndexOrThrow(DBAdapter.rKEY_TITLE));
date_created = c.getString(c.getColumnIndexOrThrow(DBAdapter.rKEY_DATE_CREATED));
comments = c.getString(c.getColumnIndexOrThrow(DBAdapter.rKEY_COMMENTS));
sample_rate = c.getString(c.getColumnIndexOrThrow(DBAdapter.rKEY_SAMPLE_RATE));
sample_rate = convertToHumanReadable(sample_rate);
duration = c.getString(c.getColumnIndexOrThrow(DBAdapter.rKEY_DURATION));
file_size = c.getString(c.getColumnIndexOrThrow(DBAdapter.rKEY_FILE_SIZE));
file_url = c.getString(c.getColumnIndexOrThrow(DBAdapter.rKEY_FILE_URL));
id = c.getString(c.getColumnIndexOrThrow(DBAdapter.rKEY_ROWID));
// find out what section was clicked on the item -- NO SOLUTION
ImageView imPlay = (ImageView) listItem.findViewById(R.id.row_play_button);
LinearLayout llFirstHalf = (LinearLayout) listItem.findViewById(R.id.row_first_half);
LinearLayout llSecondHalf = (LinearLayout) listItem.findViewById(R.id.row_second_half);
CheckBox cbCheck = (CheckBox) listItem.findViewById(R.id.row_checkbox);
}