0

私は3つのtextviews(これらのテキストビューの値はデータベースから来たもの)と1つのチェックボックスを表示するためにlistviewを使用しています。ユーザーがチェックボックスをクリックして戻ったときにチェックボックスを表示すると、チェックボックス状態を保存したいと思います。しかし、私はアンドロイドの開発に新しいと私はそれを行う方法を知りませんでした。私は、リストビューにあるチェックボックスを追加しようとしているが、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); 

} 

}); 

富士山のxmlファイルがdisabled.Belowあるさ:

<?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を有効にするにはどうすればよいですか?事前に

おかげ

答えて

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

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

これが意味をなさない場合は、ちょうどstackoverflowのビットを参照してください。この質問は何度も処理されてきました。

+0

お返事ありがとうございます。私のリストビューは動的に変更されます定数ではありません..その場合、何が答えになります..ありがとう – GoCrazy

+0

どのようにリストビューを更新する予定ですか? notifydatasetchanged()を実行するか、カーソルが変更されるたびに新しいカーソルを作成してリストビューに割り当てますか?最初のケースの場合、アダプタのコンストラクタはboolean配列の再作成を処理する必要があります。 2番目のケースの場合は、notifydatasetchanged()メソッドをオーバーライドして、リスト内の項目数の変更とその効果を実装する必要があります。 – Shubhayu

+0

こんにちは、あなたの答えに感謝します。私は最初のアプローチを使用しています。 SimpleCursorAdapterを使用してリストビューを更新しています。私はあなたの答えを試します.. – GoCrazy

関連する問題