Android列表和复选框

Android列表和复选框,第1张

概述我有一个简单的列表,从数据库中填入一个复选框.我需要一个处理所选的所有复选框.当那时按下CLEAR按钮时,我需要所有选中复选框的行ID来删除它们.去做这个 : 我的list.xml文件如下所示: < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientat 我有一个简单的列表,从数据库中填入一个复选框.我需要一个处理所选的所有复选框.当那时按下CLEAR按钮时,我需要所有选中复选框的行ID来删除它们.去做这个 :
我的List.xml文件如下所示:
< linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"            androID:orIEntation="vertical"          androID:layout_wIDth="fill_parent"          androID:layout_height="fill_parent" ><ListVIEw           androID:ID="@ID/androID:List"      androID:layout_wIDth="fill_parent"          androID:layout_height="wrap_content"          androID:layout_weight="1"          /><button        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:ID="@+ID/clearselected"        androID:text="CLEAR"        androID:clickable ="false"/> </linearLayout>

我的data_entry.xml如下所示:

<linearLayout      xmlns:androID="http://schemas.androID.com/apk/res/androID"          androID:layout_wIDth="wrap_content"          androID:layout_height="wrap_content">          <CheckBox           androID:ID="@+ID/CheckBox"           androID:layout_wIDth="wrap_content"           androID:layout_height="wrap_content"          androID:layout_x="50px"           androID:layout_y="22px"></CheckBox><TextVIEw androID:text="@+ID/EntryText"          androID:ID="@+ID/EntryText"          androID:layout_wIDth="wrap_content"          androID:layout_height="wrap_content"          androID:textAppearance="?androID:attr/textAppearanceLarge"          androID:textcolor="@color/blue"/> </linearLayout>

现在:我有List.java文件,我填写列表如下:

private voID populateList() {     Cursor c = db1.getAllList();      String[] fIElds = new String[]{db1.get_data()};       SimpleCursorAdapter cursorAdapter = new      listadapter adapter = new SimpleCursorAdapter(this,R.layout.data_entry,c,fIElds,new int[] {R.ID.EntryText});     setlistadapter(adapter);}

现在我在哪里给heckBox导致其他任何地方的句柄,它会给我一个null异常,因为data_entry包含复选框.另外我需要一个监听器来处理复选框状态?我只是坚持这一点,毫无头绪..

解决方法 为什么不使用标准的ListVIEw并启用CHOICE_MODE_MulTIPLE,而不是自己滚动?
ListVIEw.setChoiceMode(CHOICE_MODE_MulTIPLE);ListVIEw.setAdapter(new ArrayAdapter<String>(this,androID.R.layout.simple_List_item_multiple_choice,fIElds));

然后,您可以向ListVIEw询问已检查的项目.

ListVIEw.getCheckedItempositions();
总结

以上是内存溢出为你收集整理的Android列表和复选框全部内容,希望文章能够帮你解决Android列表和复选框所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1134867.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存