0

나는 listview를 사용하여 세 개의 textviews (데이터베이스에서 가져온이 텍스트보기의 값)와 하나의 확인란을 표시합니다. 사용자가 체크 박스를 클릭하고 돌아 왔을 때 체크 박스 상태를 저장하고 싶습니다. 그러나, 나는 안드로이드 개발에 새로운 사람이고 나는 그것을 어떻게하는지 전혀 모른다. , 목록보기 안드로이드에 체크리스트 상태를 저장하는 방법?

데이터베이스 및 목록보기의 목록에서 값을 검색 할 수있는 커서입니다

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 파일을 나는 목록보기에 체크 박스를 추가하는 시도하지만, onitemclick 코드가 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> 

난 두 가지 질문에 대한 답변을 얻을 경우 그것은 좋은 것,

1. 체크 박스의 상태를 저장하는 방법은 무엇입니까?

2. 확인란을 사용하는 동안 onitemclicklistener를 활성화하는 방법은 무엇입니까? 사전

답변

0
  1. 에서

    덕분에 목록 항목의 수에 부울 동일한 배열을 유지하고 상태를 저장 할 수 있지만 쉬운 방법이 없습니다. 이 값을 SimpleCursorAdapter에서 파생 된 사용자 지정 어댑터의 멤버 변수로 만들어야합니다.

  2. 다시 말해 사용자 지정 어댑터의 일부 여야합니다. 어댑터의 getView() 함수에서 onCheckedChangeListener() [지금 정확한 이름을 기억하지 마십시오] 확인란을 구현하고 listview가있는 기본 활동에서 onItemClickListener()를 목록보기.

이것이 이해가되지 않는다면, 그냥 stackoverflow에서 조금 지나가십시오. 이 질문은 여러 번 다루어졌습니다.

+0

답변 해 주셔서 감사합니다. 내 목록보기 동적으로 변경됩니다 .. 상수가 아닌 경우 그 대답은 .. 감사합니다 – GoCrazy

+0

어떻게 listview를 업데이트 할 계획입니까? 새로운 커서를 만들어 커서가 변경되거나 notifydatasetchanged()를 수행 할 때마다 listview에 할당하려고합니까? 첫 번째 경우에는 어댑터의 생성자가 부울 배열의 레크 리 에이션을 처리해야합니다. 2 번째의 경우는, notifydatasetchanged() 메소드를 오버라이드 (override) 해,리스트 내의 항목 수의 변경과 그것의 효과를 구현할 필요가 있습니다. – Shubhayu

+0

안녕하세요, 답변 해 주셔서 감사합니다. 나는 첫 번째 접근법을 사용하고있다. SimpleCursorAdapter를 사용하여 listview를 업데이트 중입니다. 답변을 시도 할 것입니다 .. – GoCrazy

관련 문제