Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Custom List Adapter image, text, sub text and checkbox
    text
    copied!<p>first, i'm sorry for my bad english and, maybe, for my stupid issues (i'm newbie). I want to implement an option panel formatted as a title. So here my code:</p> <p><strong>listview_item_row.xml</strong></p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp"&gt; &lt;ImageView android:id="@+id/imgIcon" android:contentDescription="option image" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/txtText" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/imgIcon" android:paddingLeft="15dp" android:textSize="20sp" /&gt; &lt;TextView android:id="@+id/txtSubText" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toRightOf="@id/imgIcon" android:layout_below="@id/txtText" android:paddingLeft="15dp" android:textSize="14sp" /&gt; &lt;CheckBox android:id="@+id/checkBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/txtText" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>Row.java</strong></p> <pre><code> public class Row { public int icon; public String text; public String subtext; public Row(){ super(); } public Row(int icon, String text ,String subtext) { super(); this.icon = icon; this.text = text; this.subtext = subtext; } } </code></pre> <p><strong>RowAdapter.java</strong></p> <pre><code> public class RowAdapter extends ArrayAdapter&lt;Row&gt;{ Context context; int layoutResourceId; Row data[] = null; public RowAdapter(Context context, int layoutResourceId, Row[] data) { super(context, layoutResourceId, data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Override public View getView(int position, View convertView, ViewGroup parent) { View myRow = convertView; RowHolder holder = null; if(myRow == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); myRow = inflater.inflate(layoutResourceId, parent, false); holder = new RowHolder(); holder.imgIcon = (ImageView)myRow.findViewById(R.id.imgIcon); holder.txtText = (TextView)myRow.findViewById(R.id.txtText); holder.txtSubText = (TextView)myRow.findViewById(R.id.txtSubText); holder.checkBox = (CheckBox)myRow.findViewById(R.id.checkBox); myRow.setTag(holder); } else { holder = (RowHolder)myRow.getTag(); } Row row = data[position]; holder.txtText.setText(row.text); holder.imgIcon.setImageResource(row.icon); holder.txtSubText.setText(row.subtext); return myRow; } static class RowHolder { ImageView imgIcon; TextView txtText; TextView txtSubText; CheckBox checkBox; } } </code></pre> <p>At now i dont show any checkbox when i start the activity even if i've inflate it. How can i fix this?</p> <p>Also, if I may take advantage from this question, when I have to implement the onClickListener for checkboxes how can i understand WHICH checkbox was clicked? I'll do something like this:</p> <pre><code>... Row row = data[position]; holder.txtText.setText(row.text); holder.imgIcon.setImageResource(row.icon); holder.txtSubText.setText(row.subtext); holder.check..setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if ( isChecked ) { // my code here } } }); ... </code></pre> <p>I think that "position" is the key but i dont know how can i use it.</p>
 

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