Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid: custom listview with checkbox, how to fill it
    primarykey
    data
    text
    <p>i have a listview filled by a cursor database, and with a custom xml for the row. all works well, but i need to check or uncheck a checkbox in my row, dependig of the value in the db. i don't know how.</p> <p>this is my class:</p> <pre><code> // 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&lt;HashMap&lt;String,Object&gt;&gt; data=new ArrayList&lt;HashMap&lt;String,Object&gt;&gt;(); for(int i=0;i&lt;preventiviLista.size();i++){ Preventivo_per_lista p=preventiviLista.get(i); HashMap&lt;String,Object&gt; preventivoMap=new HashMap&lt;String, Object&gt;(); 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&lt;?&gt; parent, View view,int position, long _id){ System.out.println(lista_preventivi.getItemAtPosition(position).toString()); } }); </code></pre> <p>this is my Preventivo_per_lista:</p> <pre><code>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; } } </code></pre> <p>this is my personal xml for the row</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; &lt;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" /&gt; &lt;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" /&gt; &lt;CheckBox android:id="@+id/check_preventivo" android:layout_width="20dp" android:layout_height="20dp" android:textColor="#000000" android:layout_weight="1" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>if my approvato_preventivo is 1, i need to check the checkbox, if it is 0 i need to leave it like normal.</p> <p>Can someone help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload