Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make [textview][imagebutton][checkbox] as every row in a listview
    primarykey
    data
    text
    <p>Sorry to make people confused. I simplified the question, which is the checkbox. Basically I want a listview like this, I want the checkbox be toggled when clicked.</p> <blockquote> <p>[textview][checkbox]</p> <p>[textview][checkbox]</p> <p>[textview][checkbox]</p> <p>[textview][checkbox]</p> </blockquote> <p>The problem is the checkbox cannot work correctly. When I clicked a checkbox, it never be toggled.</p> <p>Could anyone gives any suggestion? Thank you. </p> <p>This is my codes right now:</p> <pre><code>public class MyAdapter extends SimpleAdapter { Map&lt;Integer, Boolean&gt; map; LayoutInflater mInflater; private List&lt;? extends Map&lt;String, ?&gt;&gt; mList; public MyAdapter(Context context, List&lt;Map&lt;String, String&gt;&gt; data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); map = new HashMap&lt;Integer, Boolean&gt;(); mInflater = LayoutInflater.from(context); mList = data; for (int i = 0; i &lt; data.size(); i++) { map.put(i, false); } } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.rapid_diagnosis_row, null); } TextView textView = (TextView) convertView.findViewById(R.id.multiple_question); textView.setText((String) mList.get(position).get("value")); CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.multiple_checkbox); checkBox.setChecked(map.get(position)); // save position and checking status into tag checkBox.setTag(new int[] { position, checkBox.isChecked() == true ? 1 : 0 }); checkBox.setOnClickListener(new OnClickListener() { public void onClick(View v) { // get position and checking status from tag, works fine int[] tag = (int[]) (v.getTag()); int p = tag[0]; int c = tag[1]; // try to get checking status from the clicked view, not works // which is always true boolean checked = ((CheckBox) v).isChecked(); // try to toggle the clicked (checkbox) view, not works // the checkbox pressed never be toggled ((CheckBox) v).toggle(); // save status into a hashmap, works fine mSimpleAdapter.map.put(p, (c == 1 ? true : false)); } }); return convertView; } </code></pre>
    singulars
    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.
    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