i have a custom expandableListView with 2 groups . When i expand the first group everything is fine; but when i expand the second group it shows again the content from the first group. How can i fix this ??
public class MiCuentaActivity extends Fragment {
Usuario user;
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<HistorialOferta>> listDataChild;
HashMap<String, List<HistorialOferta>> listWonSubastas;
public MiCuentaActivity(Usuario user) {
// TODO Auto-generated constructor stub
this.user=user;
}
public MiCuentaActivity(){
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_mi_cuenta, container, false);
//StrictMode.enableDefaults();
expListView= (ExpandableListView) rootView.findViewById(R.id.listaExpan);
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int arg0) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(), arg0+" expandeed", Toast.LENGTH_SHORT).show();
}
});
new TareaSync().execute(new ApiConnector("cuenta", this.user));
return rootView;
}
private class TareaSync extends AsyncTask<ApiConnector, Void, HashMap<String, List<HistorialOferta>>>{
@Override
protected HashMap<String, List<HistorialOferta>> doInBackground(ApiConnector... params) {
// TODO Auto-generated method stub
listDataHeader=new ArrayList<String>();
listDataChild=new HashMap<String, List<HistorialOferta>>();
//ApiConnector api=new ApiConnector("cuenta", this.user);
List<HistorialOferta> ofertas=params[0].getCuenta();
List<HistorialOferta> lstWon=params[0].getWon();
listDataHeader.add("Historial Ofertas");
listDataHeader.add("Subastas Ganadas");
listDataChild.put(listDataHeader.get(0), ofertas);
listDataChild.put(listDataHeader.get(1), lstWon);
return listDataChild;
}
@Override
protected void onPostExecute( HashMap<String, List<HistorialOferta>> list) {
// TODO Auto-generated method stub
setListAdapter(list);
}
private void setListAdapter( HashMap<String, List<HistorialOferta>> list) {
// TODO Auto-generated method stub
expListView.setAdapter(new ExpandableList(getActivity().getApplicationContext(), listDataHeader, list));
}
}
}
Adapter:
@Override
public Object getChild(int arg0, int arg1) {
// TODO Auto-generated method stub
return this.listOfertas.get(this._listDataHeader.get(arg0)).get(arg1);
}
@Override
public View getChildView(int groupId, int childId, boolean arg2,
View convertView, ViewGroup arg4) {
// TODO Auto-generated method stub
HistorialOferta ho = (HistorialOferta) getChild(groupId, childId);
TableLayout table;
if (convertView == null) {
if(groupId==0){
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater
.inflate(R.layout.list_expand_item, null);
table = (TableLayout) convertView.findViewById(R.id.maintable);
}
if(groupId==1){
LayoutInflater infla=(LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=infla.inflate(R.layout.list_expand_won_item, null);
table=(TableLayout) convertView.findViewById(R.id.maintableWon);
}
}
return convertView;
}