我正在使用列表视图来显示三个文本视图(这些文本视图的值来自数据库)和一个复选框。我想在用户单击复选框时存储复选框状态并在他们回来时显示它。但是,我是 android 开发的新手,我不知道该怎么做。我尝试将复选框添加到列表视图,但 onitemclick 已禁用。以下是代码,
这是从数据库中检索值并在列表视图中列出的游标,
Cursor yearcursor = db.paymentall(this);
String[] yearfrom = new String[]
{ PaymentAppDataBase.REQUESTEDDATE,PaymentAppDataBase.PAYMENTNAME,PaymentAppDataBase.AMOUNT };
int[] yearto = new int[] { R.id.Date,R.id.Name,R.id.Amount };
SimpleCursorAdapter yearadapter =
new SimpleCursorAdapter(this, R.layout.listview, yearcursor, yearfrom, yearto);
setListAdapter(yearadapter);
amount.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Cursor cursor = (Cursor) parent.getItemAtPosition(position);
String toaddressreview = cursor.getString(4);
String subjectreview = cursor.getString(5);
String emailbodyreview = cursor.getString(6);
Intent todayreview = new Intent(ReviewPayment.this,ReviewandResend.class);
todayreview.putExtra("toadd", toaddressreview);
todayreview.putExtra("subjectreveiew", subjectreview);
todayreview.putExtra("emailbody", emailbodyreview);
startActivity(todayreview);
}
});
MT.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/Date"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:textSize="14sp"/>
<TextView android:id="@+id/Name"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:layout_weight="2"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:layout_toRightOf="@+id/Date"/>
<TextView android:id="@+id/Amount"
android:layout_width="50dip"
android:layout_height="20dip"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:layout_weight="2"
android:layout_toRightOf="@+id/Name"/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="50dip"
android:layout_alignBottom="@+id/Amount"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/Amount" />
</RelativeLayout>
如果我能得到两个问题的答案,那就太好了,
1.如何保存复选框的状态?
2.使用复选框时如何启用onitemclicklistener?
提前致谢