Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Custom Expandeble List and CheckBox issue. Why is chechbox state random?
    primarykey
    data
    text
    <p>Problem is this:</p> <p><a href="http://img204.imageshack.us/img204/6071/immaginety.png" rel="nofollow">http://img204.imageshack.us/img204/6071/immaginety.png</a></p> <p>Why happens that ?? If i check near "Media" and expand node, checkmark goes to second child. I dont understand why</p> <p><strong>EDIT1</strong>: solved checkBox state. Another problem occurs!!</p> <p>But, maybe i have just understood that the problem isn't checkBox state!!! The problem is the position of rows that switch! If i put an array for checking when a view is just loaded, checkBox state works well! The problem is view position! This is what happens:</p> <pre><code>row0: parentA + checkBoxMARKED row1: parentB + checkBoxNOTmarked </code></pre> <p>click on A, and this is supposed to happen:</p> <pre><code>row0: parentA + checkBoxMARKED subRow0: --childA row1: parentB + checkBoxNOTmarked </code></pre> <p>but, on the contrary, this occurs (a parent switch)</p> <pre><code>row1: parentB + checkBoxNOTmarked subRow0: --childA row0: parentA + checkBoxMarked </code></pre> <p>Now, if i comment this line</p> <pre><code>if(usedPositionParent.contains(convertView.getId())){ return convertView; } else{ usedPositionParent.add(convertView.getId()); } </code></pre> <p>Situation becomes:</p> <pre><code>row0: parentA + checkBoxMARKED row1: parentB + checkBoxNOTmarked </code></pre> <p>click on A, and occurs:</p> <pre><code>row1: parentA + checkBoxNOTmarked subRow1: --childA row0: parentB + checkBoxMARKED </code></pre> <p>But in reality, parentA is Row 0 !!! So it doesn't appear a checkBox problem. It's a parent position problem!! What are you think about ?</p> <p>This is new code:</p> <pre><code>public class ListaEspandibileAdapter extends BaseExpandableListAdapter { private ArrayList&lt;Object&gt; _objInt; Context mContext; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //HashMap&lt;Integer,Boolean&gt; checkboxMap = new HashMap&lt;Integer,Boolean&gt;(); CheckListener checkListner; ArrayList&lt;Integer&gt; usedPositionParent = new ArrayList&lt;Integer&gt;(); CheckBox checkBox; public ListaEspandibileAdapter(Context context, ArrayList&lt;Object&gt; objList){ mContext = context; _objInt = objList; popolaCheckMap(); } public void popolaCheckMap(){ for(int i=0; i&lt; _objInt.size(); i++) checkboxMap.put(i, false); } @Override public Object getChild(int arg0, int arg1) { return null; } @Override public long getChildId(int groupPos, int childPos) { return childPos; } @Override public View getChildView(int groupPos, int childPos, boolean arg2, View convertView, ViewGroup parent) { if (convertView == null) { Log.i("childView", "my parent is "+ groupPos); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.opportunita_cella_child, null); EditText descrizioneEditText = (EditText) convertView.findViewById(R.id.opportunita_child_descrizione); Intervento i = (Intervento) _objInt.get(groupPos); descrizioneEditText.setText(i.descrizione); } return convertView; } @Override public int getChildrenCount(int arg0) { // i have always one child! return 1; } @Override public Object getGroup(int arg0) { return null; } @Override public int getGroupCount() { return _objInt.size(); } @Override public long getGroupId(int groupPos) { return groupPos; } @Override public View getGroupView(int groupPos, boolean isExpanded, View convertView, ViewGroup parent) { if(convertView == null) { Log.i("parentView", "I'am "+ groupPos); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.opportunita_cella, null); convertView.setId(groupPos); checkBox = (CheckBox) convertView.findViewById(R.id.opportunita_checkbox); checkBox.setFocusable(false); CheckListener checkL = new CheckListener(); checkL.setPosition(groupPos); checkBox.setOnCheckedChangeListener(checkL); Intervento intervento = (Intervento) _objInt.get(groupPos); ImageView imageView = (ImageView) convertView.findViewById(R.id.opportunita_image); TextView tipoText = (TextView) convertView.findViewById(R.id.opportunita_tipo); TextView oggettoText = (TextView) convertView.findViewById(R.id.opportunita_oggetto); TextView urgenzaText = (TextView) convertView.findViewById(R.id.opportunita_urgenza); TextView dataText = (TextView) convertView.findViewById(R.id.opportunita_data); TextView oraText = (TextView) convertView.findViewById(R.id.opportunita_ora); if(intervento.getTipo().equals("Guasto")) imageView.setImageResource(R.drawable.ic_intervento); else if(intervento.getTipo().equals("Programmato")) imageView.setImageResource(R.drawable.image_programmato); tipoText.setText(intervento.tipo); oggettoText.setText(intervento.oggetto); urgenzaText.setText(intervento.urgenza); if(intervento.urgenza.equals("Immediata")) urgenzaText.setTextColor(Color.RED); else if(intervento.urgenza.equals("Alta")) urgenzaText.setTextColor(Color.YELLOW); else if(intervento.urgenza.equals("Media")) urgenzaText.setTextColor(Color.GREEN); else if(intervento.urgenza.equals("Bassa")) urgenzaText.setTextColor(Color.WHITE); Date d = null; try { d = sdf.parse(intervento.data); } catch (ParseException e) { e.printStackTrace(); } String yyyy = String.valueOf(d.getYear()+1900); String MM = String.valueOf(d.getMonth()+1); String gg = String.valueOf(d.getDate()); String hh = String.valueOf(d.getHours()); String mm = String.valueOf(d.getMinutes()); if(Integer.parseInt(MM) &lt;= 9) MM = "0"+MM; if(Integer.parseInt(gg) &lt;= 9) gg = "0"+gg; if(Integer.parseInt(hh) &lt;= 9) hh = "0"+hh; if(Integer.parseInt(mm) &lt;= 9) mm = "0"+mm; dataText.setText(gg+"-"+MM+"-"+yyyy); oraText.setText(hh+":"+mm); } if(usedPositionParent.contains(convertView.getId())){ //checkBox.setChecked(checkboxMap.get(groupPos)); return convertView; } else{ usedPositionParent.add(convertView.getId()); } //if(isExpanded) // checkBox.setChecked(checkboxMap.get(groupPos)); return convertView; } @Override public boolean hasStableIds() { return false; } @Override public boolean isChildSelectable(int arg0, int arg1) { return false; } public class CheckListener implements OnCheckedChangeListener{ int pos; public void setPosition(int p){ pos = p; } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Log.i("checkListenerChanged", String.valueOf(pos)+":"+String.valueOf(isChecked)); //checkboxMap.put(pos, isChecked); } } </code></pre> <p>}</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.
    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