Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get id of check boxes in expanded list view item?
    primarykey
    data
    text
    <p>I have an expanded list view that have check boxes in parent nodes as well as child items. all data comes from web service so its dynamic.</p> <p>Image attached:</p> <p><img src="https://i.stack.imgur.com/hvjd1.png" alt="enter image description here"></p> <p>Now on menu item click i want to fetch all check box status . please guide me how can i get id of check boxes used in it.</p> <p>code attached:</p> <pre><code>/** * */ public class Object_SecurityActivity extends ExpandableListActivity { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // TODO Auto-generated method stub return super.onChildClick(parent, v, groupPosition, childPosition, id); } @Override public void onContentChanged() { // TODO Auto-generated method stub super.onContentChanged(); } private AndroidClientEntity obj_android_client; private static final String LOG_TAG = "ElistCBox2"; private String username, password, clientname; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); //setContentView(R.layout.main); Intent security_intent = getIntent(); String id = security_intent.getStringExtra("id"); obj_android_client = (AndroidClientEntity) getApplicationContext(); username = obj_android_client.getUsername(); password = obj_android_client.getPassword(); clientname = obj_android_client.getClientName(); new Securityasync().execute(username, password, clientname, id); } class Securityasync extends AsyncTask&lt;String, String, String&gt; { String sesurity_response = null; ProgressDialog dialog; private Expandable_list_Adapter expListAdapter; @Override protected String doInBackground(String... params) { if ((isOnline(Object_SecurityActivity.this).equals("true"))) { Security_service security_obj = new Security_service(); try { sesurity_response = security_obj.getUsersRoles(params[0], params[1], params[2], params[3]); } catch (IllegalStateException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return null; } @Override protected void onPostExecute(String result) { if (isOnline(Object_SecurityActivity.this).equals("true")) { setContentView(R.layout.layout_expandable_listview); ArrayList&lt;String&gt; groupNames = new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; sub = new ArrayList&lt;String&gt;(); ArrayList&lt;ArrayList&lt;String&gt;&gt; child = new ArrayList&lt;ArrayList&lt;String&gt;&gt;(); ArrayList&lt;String&gt; sub_id = new ArrayList&lt;String&gt;(); ArrayList&lt;String&gt; objrid = new ArrayList&lt;String&gt;(); try { JSONArray json = new JSONArray(sesurity_response); // JSONArray json_child=new JSONArray(sesurity_response); for (int i = 0; i &lt; json.length(); i++) { JSONObject json_obj = json.getJSONObject(i); if (json_obj.getString("PRid").equalsIgnoreCase("0")) { String ObjectRid = json_obj.getString("ObjectRid"); int m=0; objrid.add(m,ObjectRid); m++; groupNames.add(json_obj.getString("Name")); for (int j = 0; j &lt; json.length(); j++) { JSONObject json_child = json.getJSONObject(j); if (ObjectRid.equalsIgnoreCase(json_child .getString("PRid"))) { int n=0; sub_id.add(n,json_child.getString("ObjectRid")); sub.add(json_child.getString("Name")); } } child.add(sub); } } expListAdapter = new Expandable_list_Adapter(getBaseContext(), groupNames, child); setListAdapter(expListAdapter); Log.e("size in error", "son " + json.length()); } catch (JSONException e) { Log.e("", "", e); Toast.makeText(getBaseContext(), "parsing error", Toast.LENGTH_LONG).show(); } Log.e("sizeof list", ""+sub_id.size()); Iterator itr=objrid.iterator(); while(itr.hasNext()){ Log.e("id","value "+itr.next()); } } } @Override protected void onPreExecute() { super.onPreExecute(); } } } </code></pre> <p>And adapter class:</p> <pre><code>public class Expandable_list_Adapter extends BaseExpandableListAdapter implements OnCheckedChangeListener { private Context context; private ArrayList&lt;String&gt; groupNames; private ArrayList&lt;ArrayList&lt;String&gt;&gt; child; private LayoutInflater inflater; public Expandable_list_Adapter(Context context, ArrayList&lt;String&gt; groupNames, ArrayList&lt;ArrayList&lt;String&gt;&gt; child ) { this.context = context; this.groupNames= groupNames; this.child = child; inflater = LayoutInflater.from( context ); } public Object getChild(int groupPosition, int childPosition) { return child.get( groupPosition ).get( childPosition ); } public long getChildId(int groupPosition, int childPosition) { return (long)( groupPosition*1024+childPosition ); // Max 1024 children per group } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { View v = null; if( convertView != null ) v = convertView; else v = inflater.inflate(R.layout.child_row, parent, false); String c = (String)getChild( groupPosition, childPosition ); TextView color = (TextView)v.findViewById( R.id.childname ); if( color != null ) color.setText( c ); CheckBox cb = (CheckBox)v.findViewById( R.id.check1 ); //cb.setChecked(false); cb.setOnCheckedChangeListener(this); return v; } public int getChildrenCount(int groupPosition) { return child.get( groupPosition ).size(); } public Object getGroup(int groupPosition) { return groupNames.get( groupPosition ); } public int getGroupCount(){ return groupNames.size(); } public long getGroupId(int groupPosition) { return (long)( groupPosition*1024 ); // To be consistent with getChildId } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { View v = null; if( convertView != null ) v = convertView; else v = inflater.inflate(R.layout.group_row, parent, false); String gt = (String)getGroup( groupPosition ); TextView colorGroup = (TextView)v.findViewById( R.id.childname ); if( gt != null ) colorGroup.setText( gt ); CheckBox cb = (CheckBox)v.findViewById( R.id.check2 ); cb.setChecked(false); return v; } public boolean hasStableIds() { return true; } public boolean isChildSelectable(int groupPosition, int childPosition) { Log.e("is group checked","group "+groupPosition); Log.e("selectable","has" +childPosition); return true; } public void onGroupCollapsed (int groupPosition) {} public void onGroupExpanded(int groupPosition) {} public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub } public void isChecked(){ } } </code></pre> <p>Child.xml </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:background="#21415A" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;TextView android:id="@+id/childname" android:paddingLeft="50px" android:focusable="false" android:textSize="14px" android:textStyle="italic" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; &lt;TextView android:id="@+id/rgb" android:focusable="false" android:textSize="14px" android:textStyle="italic" android:layout_width="100px" android:layout_height="wrap_content"/&gt; &lt;CheckBox android:id="@+id/check1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:focusable="false" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>parent.xml is same as child.</p> <p>please guide me how can i get ids of check boxes because on menu item selected i have to do operation basics on that.</p> <p>Edit: i tried to setTag() and getTag() . but now expandable list view is showing strange behavior. when i select an checkbox and expand another group all chekbok boxes is set to default. What i have to do in this case. i dont know the resion why it is not saving state. i am faceing same problem as <a href="https://stackoverflow.com/questions/3633823/strange-behaviour-in-expandablelistview-android">Strange behaviour in Expandablelistview - Android</a> Plz guide </p>
    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.
 

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