
我的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列表和复选框所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)