0

リストビューを使用して、3 つのテキストビュー (データベースから取得したこれらのテキスト ビューの値) と 1 つのチェックボックスを表示しています。ユーザーがチェックボックスをクリックするたびにチェックボックスの状態を保存し、戻ってきたときに表示したいと思います。しかし、私は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>

2つの質問に答えてもらえると嬉しいのですが、

1.チェックボックスの状態を保存するには?

2.チェックボックスの使用中に onitemclicklistener を有効にする方法は?

前もって感謝します

4

1 に答える 1

0
  1. 簡単な方法はありませんが、リスト項目の数に等しいブール値の配列を保持し、状態を保存することです。これを、SimpleCursorAdapter から派生するカスタム アダプターのメンバー変数にする必要があります。

  2. 繰り返しますが、これはカスタム アダプターの一部である必要があります。アダプターの getView() 関数で、チェックボックスの onCheckedChangeListener() [今は正確な名前を思い出さないでください] を実装する必要があり、リストビューがあるメインのアクティビティで onItemClickListener() をリストビュー。

これが意味をなさない場合は、stackoverflow で少し調べてみてください。この質問は何度も取り上げられてきました。

于 2012-04-09T18:09:25.470 に答える