复选框列表视图中使用自定义SimpleCurser结合 [英] Checkbox in listview with Custom SimpleCurser binding

查看:128
本文介绍了复选框列表视图中使用自定义SimpleCurser结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为香港专业教育学院尝试了一切(由可聚焦:假的!) ,我不能捕捉反正我的名单上项目选中的复选框。 甚至OnItemClickListener,那并不响应任何点击。

i think ive tried everything(made focusable:false!!) and i cant capture in anyway the selected checkbox on my list item. even OnItemClickListener, doesnt respond to any click.

我怎样才能找回我的列表项选中的复选框? 我的列表项inclused:图像显示,4 textviews和复选框

how can i retrieve checked checkboxes in my list item? my list item inclused: image view, 4 textviews and the checkbox

约code:

这是在我的ListActivity类:

this is in my ListActivity class:

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); 

这是我的自定义光标适配器类:

and this is my Custom Cursor adapter class:

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); 
} 

我会AP preciate任何帮助!它是真正去pressing,我尝试过很多办法。许多听众,想不通如何捕获侦听器,以我的复选框。

I will appreciate any help! it's really depressing, I've tried many ways. many listeners, can't figure how to capture listener to my checkboxes.

我绑定从数据库列表项的数据,​​是不是concered关于复选框..只有textviews ..没有数据库和复选框我在列表中的项目之间有任何联系。

The data I am binding to the list items from the database, isn't concered about the checkbox.. only the textviews.. there isn't any connection between the database and the checkbox I have in the list's item.

谢谢, IDAN。

<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的内置的多项选择列表的支持( CHOICE_MODE_MULTIPLE )。

I would recommend you use Android's built-in support for multiple-choice lists (CHOICE_MODE_MULTIPLE).

的<一个href="http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/view/List11.html"><$c$c>List11.java SDK示例演示了这一点。您也可以找到我的教程一个使用它这里的项目。

您仍可以使用此技术与自己的布局,只要你有一个 CheckedTextView 机器人:ID =@机器人:ID / text1中的如图所示 android.R.layout.simple_list_item_multiple_choice 资源中,它随你的SDK,副本

You can still use this technique with your own layout, so long as you include a CheckedTextView with android:id="@android:id/text1" as shown in the android.R.layout.simple_list_item_multiple_choice resource, a copy of which ships with your SDK.

这篇关于复选框列表视图中使用自定义SimpleCurser结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆