我有一个问题,被困了一段时间,
我不知道如何在列表中添加一个复选框,例如,如果我有一个项目列表,我希望能够检查它们.我的xml代码如下:
<linearLayout androID:ID="@+ID/topLayout" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_centerHorizontal="true" androID:layout_height="wrap_content"></linearLayout><linearLayout androID:ID="@+ID/mIDdleLayout" androID:orIEntation="horizontal" androID:layout_height="wrap_content" androID:layout_wIDth="fill_parent"> <linearLayout androID:ID="@+ID/leftMIDdleLayout" androID:orIEntation="vertical" androID:layout_below="@+ID/topLayout" androID:layout_above="@+ID/bottomLayout" androID:layout_wIDth="60px" androID:layout_height="wrap_content" > <ListVIEw androID:ID="@+ID/checkBoxList" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" ></ListVIEw> <CheckBox androID:ID="@+ID/checkBox" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:checked="false" androID:text="test"> </CheckBox> </linearLayout> <linearLayout androID:ID="@+ID/rightmIDdleLayout" androID:orIEntation="vertical" androID:layout_below="@+ID/topLayout" androID:layout_above="@+ID/bottomLayout" androID:layout_wIDth="280px" androID:layout_height="wrap_content" > <ListVIEw androID:ID="@+ID/List" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" ></ListVIEw> <TextVIEw androID:ID="@+ID/text" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"/> </linearLayout></linearLayout><linearLayout androID:ID="@+ID/bottomLayout" androID:layout_alignParentBottom="true" androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:paddingBottom="5pt" > <EditText androID:ID="@+ID/insertNewItem" androID:layout_wIDth="220px" androID:layout_height="wrap_content" /> <TextVIEw androID:layout_wIDth="10px" androID:layout_height="wrap_content" /> <button androID:ID="@+ID/addItembutton" androID:layout_wIDth="wrap_content" androID:layout_height="fill_parent" androID:text="Add Item"/></linearLayout>
如果您有任何想法,请告诉我,我的学术研究:((
谢谢!
解决方法:
public class myAdapter extends SimpleCursorAdapter { public myAdapter(Context context, int layout, Cursor cursor, String[] from, int[] to) { super(context, layout, cursor, from, to); }@OverrIDe public voID bindVIEw(VIEw vIEw, Context context, Cursor cursor) { cb=(CheckBox)vIEw.findVIEwByID(R.ID.cb); cb.setText(dbgetStringValue); cbText=(TextVIEw)vIEw.findVIEwByID(R.ID.cbText); cbText.setText(dbgetStringValue); cb.setChecked(false); cb.setonCheckedchangelistener(new OnCheckedchangelistener() { public voID onCheckedChanged(Compoundbutton cb, boolean isChecked) { if(cb.isChecked()) { // action } else if(isChecked==false) { // action } } });}}
那是你要的吗?
总结以上是内存溢出为你收集整理的android – 如何在listview中添加复选框?全部内容,希望文章能够帮你解决android – 如何在listview中添加复选框?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)