我想我已经尝试了所有东西(使焦点成为可能:假!!)并且无论如何我无法捕捉列表项目中的所选复选框.即使是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);
Run Code Online (Sandbox Code Playgroud)
这是我的Custom Cursor适配器类:
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);
}
Run Code Online (Sandbox Code Playgroud)
我将不胜感激任何帮助!它真的令人沮丧,我尝试了很多方法.很多听众,无法想象如何捕获我的复选框的监听器.
我绑定到数据库中的列表项的数据,并不是关于复选框..只有textviews ..数据库和列表项目中的复选框之间没有任何连接.
谢谢,艾丹.
<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>
Run Code Online (Sandbox Code Playgroud)
我建议您使用Android的内置支持多选列表(CHOICE_MODE_MULTIPLE
).
该List11.java
SDK示例演示了这一点.您也可以找到我的教程的一个使用它的一个项目在这里.
您仍然可以将此技术用于您自己的布局,只要您在资源中包含一个CheckedTextView
with ,其副本随SDK一起提供.android:id="@android:id/text1"
android.R.layout.simple_list_item_multiple_choice
归档时间: |
|
查看次数: |
12729 次 |
最近记录: |