カーソルデータベースと行のカスタムxmlで満たされたリストビューがあります。すべてうまくいきますが、データベースの値に応じて、行のチェックボックスをオンまたはオフにする必要があります。方法がわかりません。
これは私のクラスです:
// inserisco gli elementi
db.open();
Cursor prendi_preventivi=db.prendi_preventivi();
while(prendi_preventivi.moveToNext()){
String nome_preventivo=prendi_preventivi.getString(prendi_preventivi.getColumnIndex("nome"));
String data_preventivo=prendi_preventivi.getString(prendi_preventivi.getColumnIndex("data"));
int approvato_preventivo=Integer.parseInt(prendi_preventivi.getString(prendi_preventivi.getColumnIndex("approvato")));
preventiviLista.add(new Preventivo_per_lista(nome_preventivo,data_preventivo,approvato_preventivo));
}
db.close();
ArrayList<HashMap<String,Object>> data=new ArrayList<HashMap<String,Object>>();
for(int i=0;i<preventiviLista.size();i++){
Preventivo_per_lista p=preventiviLista.get(i);
HashMap<String,Object> preventivoMap=new HashMap<String, Object>();
preventivoMap.put("nome", p.getNome());
preventivoMap.put("data", p.getData());
data.add(preventivoMap);
}
String[] from={"nome","data"};
int[] to={R.id.nome_preventivo,R.id.data_preventivo};
SimpleAdapter adapter=new SimpleAdapter(getApplicationContext(),data,R.layout.elemento_preventivo,from,to);
lista_preventivi.setAdapter(adapter);
lista_preventivi.setOnItemClickListener(new OnItemClickListener(){
// click di elemento
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long _id){
System.out.println(lista_preventivi.getItemAtPosition(position).toString());
}
});
これは私の Preventivo_per_lista です:
public class Preventivo_per_lista{
private String nome;
private String data;
private int approvato;
public Preventivo_per_lista(String name,String data,int approvato){
super();
this.nome=name;
this.data=data;
this.approvato=approvato;
}
public String getNome(){
return nome;
}
public String getData(){
return data;
}
public int getApprovato(){
return approvato;
}
}
これは、行の個人的な xml です
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:orientation="horizontal"
android:id="@+id/elemento_preventivo"
android:weightSum="3">
<TextView android:id="@+id/nome_preventivo"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:textColor="#000000"
android:layout_weight="1"
android:textStyle="bold" />
<TextView android:id="@+id/data_preventivo"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:textColor="#000000"
android:layout_weight="1"
android:textStyle="bold" />
<CheckBox android:id="@+id/check_preventivo"
android:layout_width="20dp"
android:layout_height="20dp"
android:textColor="#000000"
android:layout_weight="1" />
</LinearLayout>
appprovato_preventivo が 1 の場合は、チェックボックスをオンにする必要があります。0 の場合は、通常どおりにしておく必要があります。
誰かが私を助けることができますか?