【发布时间】:2011-01-16 17:27:13
【问题描述】:
我想我什么都试过了(变得可聚焦:假!!) 而且我无论如何都无法捕获列表项上选定的复选框。 即使是 OnItemClickListener,也不响应任何点击。
如何在我的列表项中检索选中的复选框? 我的列表项包括:图像视图、4 个文本视图和复选框
一些代码:
这是在我的 ListActivity 类中:
final String columns[] = new String[] { MyUsers.User._ID,
MyUsers.User.MSG, MyUsers.User.LOCATION };
int[] to = new int[] { R.id.toptext, R.id.bottomtext,R.id.ChkBox, R.id.Location};
Uri myUri = Uri.parse("content://com.idan.datastorageprovider/users");
Cursor cursor = getContentResolver().query(myUri, columns, null, null, null);
startManagingCursor(cursor);
ListCursorAdapter myCursorAdapter=new ListCursorAdapter(this,
R.layout.listitem, cursor, columns, to);
this.setListAdapter(myCursorAdapter);
这是我的自定义光标适配器类:
public class ListCursorAdapter extends SimpleCursorAdapter
{
private Context context;
private int layout;
public ListCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to)
{
super(context, layout, c, from, to);
this.context = context;
this.layout = layout;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent)
{
Cursor c = getCursor();
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
return v;
}
@Override
public void bindView(View v, Context context, Cursor c)
{
TextView topText = (TextView) v.findViewById(R.id.toptext);
if (topText != null)
{
topText.setText("");
}
int nameCol = c.getColumnIndex(MyUsers.User.MSG);
String name = c.getString(nameCol);
TextView buttomTxt = (TextView) v.findViewById(R.id.bottomtext);
if (buttomTxt != null)
{
buttomTxt.setText("Message: "+name);
}
nameCol = c.getColumnIndex(MyUsers.User.LOCATION);
name = c.getString(nameCol);
TextView location = (TextView) v.findViewById(R.id.Location);
if (locationLinkTxt != null)
{
locationLinkTxt.setText(name);
}
我将不胜感激!真的很郁闷,试过很多方法。许多听众,不知道如何将听众捕捉到我的复选框。
我从数据库绑定到列表项的数据,不关心复选框..只有文本视图..数据库和我在列表项中的复选框之间没有任何连接。
谢谢, 伊丹
<ImageView
android:id="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dip"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="@drawable/icon" >
</ImageView>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="1sp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical" >
<TextView
android:id="@+id/toptext"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical"
android:singleLine="true"
android:text="OrderNum" >
</TextView>
<TextView
android:id="@+id/bottomtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="TweetMsg" >
</TextView>
<TextView
android:id="@+id/twittLocation"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:singleLine="true"
android:text="location" >
</TextView>
<TextView
android:id="@+id/twittLocationlink"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="fill_horizontal"
android:text="locationlink" >
</TextView>
</LinearLayout>
<CheckBox
android:id="@+id/deleteTwittChkBox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="2dp"
android:checked="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Delete" >
</CheckBox>
【问题讨论】:
标签: android