Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to find other (checkbox)view in a custom listview
    primarykey
    data
    text
    <p>I am new so I may not explain the situation well. Please let me know if you need more info.</p> <p>I am trying to implement a listview like this:</p> <pre><code> [textview][button][checkbox] [textview][button][checkbox] [textview][button][checkbox] [textview][button][checkbox] </code></pre> <p>I want other checkbox unchecked automatically when I click one of them. So it is like a single choice. I write following codes which can implement multiple choice but when I try to switch it to single choice I got trouble. </p> <p>in checkBoxOnClickListener I cannot find other (checkbox)view and toggle them. Any suggestion pals? Let me know if you think my express skills poor.</p> <p>Thank you.</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); } if (data.get(0).get("value").equals("Male") || data.get(0).get("value").equals("Yes")) { map.put(1, true); } } @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(position); checkBox.setOnClickListener(checkBoxOnClickListener); return convertView; } public OnClickListener checkBoxOnClickListener = new OnClickListener() { public void onClick(View v) { // ((CheckBox) v).toggle(); boolean checked = ((CheckBox) v).isChecked(); if (checked) { ((CheckBox) v).setChecked(true); } else { ((CheckBox) v).setChecked(false); } int p = (Integer) (v.getTag()); mSimpleAdapter.map.put(p, checked); // this cannot works, helppp ListView lv = ((ListView) (v.getParent().getParent())); (CheckBox) cb = lv.findViewWithTag(1); cb.toggle(); ..................... </code></pre> <p>............... } }; }</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.
    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