Note that there are some explanatory texts on larger screens.

plurals
  1. PORadio button changes state on scroll of Sectioned Listview
    primarykey
    data
    text
    <p>I am using the <code>Sectioned ListView</code> in my application in the row of <code>ListView</code> i have <code>TextView</code> and <code>RadioGroup.</code> So when i click the radio button normally it gets clicked and works fine. But when i click and scroll the view it the selected view's also get vanished and becomes unchecked.</p> <p>This is the XML i am using</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativelay" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/list_bg" &gt; &lt;TextView android:id="@+id/tvname" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:maxLines="1" android:padding="10dp" android:textColor="#000000" android:textSize="18dp" android:textStyle="bold" /&gt; &lt;RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:orientation="horizontal" &gt; &lt;RadioButton android:id="@+id/check_present" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="20dp" android:onClick="onPresentClick" /&gt; &lt;RadioButton android:id="@+id/check_absent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/check_present" android:onClick="onPresentClick" /&gt; &lt;/RadioGroup&gt; &lt;/RelativeLayout&gt; </code></pre> <p>And this is the adapter i am using for the <code>Sectioned ListView</code>....</p> <p>This is my updated code....</p> <pre><code>public class NamesAdapter extends ArrayAdapter&lt;Item&gt; { private ArrayList&lt;Item&gt; items; private LayoutInflater vi; private Item objItem; private ArrayList&lt;Items&gt; presentSelected = new ArrayList&lt;Items&gt;();; private ArrayList&lt;Items&gt; absentSelected = new ArrayList&lt;Items&gt;();; private Map&lt;Integer, Boolean&gt; map = new HashMap&lt;Integer, Boolean&gt;(); ViewHolderSectionName holderSection; ViewHolderName holderName; Items item; public NamesAdapter(Context context, ArrayList&lt;Item&gt; items) { super(context, 0, items); this.items = items; vi = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(final int position, View convertView, ViewGroup parent) { objItem = items.get(position); if (objItem.isSectionItem()) { ItemsSections si = (ItemsSections) objItem; if (convertView == null || !convertView.getTag().equals(holderSection)) { convertView = vi.inflate(R.layout.alphabet_separator, null); holderSection = new ViewHolderSectionName(); convertView.setTag(holderSection); } else { holderSection = (ViewHolderSectionName) convertView.getTag(); } holderSection.section = (TextView) convertView .findViewById(R.id.alphabet_letter); holderSection.section .setText(String.valueOf(si.getSectionLetter())); } else { Items ei = (Items) objItem; if (convertView == null || !convertView.getTag().equals(holderName)) { convertView = vi.inflate(R.layout.row, null); holderName = new ViewHolderName(); holderName.name = (TextView) convertView .findViewById(R.id.tvname); holderName.radioGroup = (RadioGroup) convertView .findViewById(R.id.radioGroup1); holderName.checkAbsent = (RadioButton) convertView .findViewById(R.id.check_absent); holderName.checkPresent = (RadioButton) convertView .findViewById(R.id.check_present); Boolean present = map.get(position); Log.e("Names Adapter", "is Selected " + present); if (present != null &amp;&amp; present.booleanValue()) { // set present checkbox selected holderName.checkPresent.setSelected(true); } else { holderName.checkAbsent.setSelected(true); // set absent checkbox selected } holderName.radioGroup .setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub switch (checkedId) { case R.id.check_absent: item = (Items) holderName.checkAbsent .getTag(); absentSelected.add(item); map.put(position, true); break; case R.id.check_present: item = (Items) holderName.checkPresent .getTag(); presentSelected.add(item); map.put(position, true); break; default: break; } } }); /* * holderName.checkAbsent .setOnCheckedChangeListener(new * CompoundButton.OnCheckedChangeListener() { * * @Override public void onCheckedChanged( CompoundButton * buttonView, boolean isChecked) { // TODO Auto-generated * method stub holderName.checkAbsent.setSelected(isChecked); // * selected1.add(); * * } }); * * holderName.checkPresent .setOnCheckedChangeListener(new * CompoundButton.OnCheckedChangeListener() { * * @Override public void onCheckedChanged( CompoundButton * buttonView, boolean isChecked) { // TODO Auto-generated * method stub holderName.checkAbsent.setSelected(isChecked); // * selected2.add(); * * } }); */ convertView.setTag(holderName); } else { holderName = (ViewHolderName) convertView.getTag(); } if (holderName.name != null) holderName.name.setText(ei.getName()); convertView.setOnCreateContextMenuListener(null); } return convertView; } public static class ViewHolderName { public TextView name; public RadioGroup radioGroup; public RadioButton checkPresent; public RadioButton checkAbsent; } public static class ViewHolderSectionName { public TextView section; } } </code></pre>
    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.
 

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