Проблема заключается в следующем:
http://img204.imageshack.us/img204/6071/immaginety.png
Почему так происходит ??
Если я проверяю рядом с «Media» и раскрываю узел, флажок переходит ко второму дочернему элементу.
Я не понимаю, почему
EDIT1 : решено состояние checkBox. Возникает другая проблема !!
Но, может быть, я только что понял, что проблема не в состоянии checkBox !!! Проблема заключается в положении строк, которые переключаются! Если я помещу массив для проверки, когда представление только что загружено, состояние checkBox работает хорошо! Проблема в положении взгляда! Вот что происходит:
row0: parentA + checkBoxMARKED
row1: parentB + checkBoxNOTmarked
нажмите на A, и это должно произойти:
row0: parentA + checkBoxMARKED
subRow0: --childA
row1: parentB + checkBoxNOTmarked
но, наоборот, это происходит (родительский переключатель)
row1: parentB + checkBoxNOTmarked
subRow0: --childA
row0: parentA + checkBoxMarked
Теперь, если я прокомментирую эту строку
if(usedPositionParent.contains(convertView.getId())){
return convertView;
}
else{
usedPositionParent.add(convertView.getId());
}
Ситуация становится:
row0: parentA + checkBoxMARKED
row1: parentB + checkBoxNOTmarked
нажмите на A, и произойдет:
row1: parentA + checkBoxNOTmarked
subRow1: --childA
row0: parentB + checkBoxMARKED
Но на самом деле parentA - это строка 0 !!! Так что это не появляется проблема checkBox. Это проблема родительской позиции !! О чем вы думаете?
Это новый код:
public class ListaEspandibileAdapter extends BaseExpandableListAdapter {
private ArrayList<Object> _objInt;
Context mContext;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//HashMap<Integer,Boolean> checkboxMap = new HashMap<Integer,Boolean>();
CheckListener checkListner;
ArrayList<Integer> usedPositionParent = new ArrayList<Integer>();
CheckBox checkBox;
public ListaEspandibileAdapter(Context context, ArrayList<Object> objList){
mContext = context;
_objInt = objList;
popolaCheckMap();
}
public void popolaCheckMap(){
for(int i=0; i< _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) <= 9)
MM = "0"+MM;
if(Integer.parseInt(gg) <= 9)
gg = "0"+gg;
if(Integer.parseInt(hh) <= 9)
hh = "0"+hh;
if(Integer.parseInt(mm) <= 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);
}
}
}