By clicking a button, I get to appear a Dialog, with a ExpandableListView in its layout, being populated with checkboxes:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog=new Dialog(MainActivity.this);
dialog.setContentView(R.layout.selectdialoglayout);
elv=(ExpandableListView) dialog.findViewById(R.id.elv);
setParentsItems();
setChildData();
MyExpandableAdapter adapter = new MyExpandableAdapter(parents, childs);
adapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), MainActivity.this);
elv.setAdapter(adapter);
elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
String componente="";
if(i==0){
componente=childsIuGeneral.get(i1);
}
if(i==1){
componente=childsIuSuelo.get(i1);
}
if(i==2){
componente=childsIuCon.get(i1);
}
if(i==3){
componente=childsIuComp.get(i1);
}
if(i==4){
componente=childsIuAmort.get(i1);
}
Log.i("LOG", "Componente seleccionado: "+componente);
return true;
}
});
Button close=(Button)dialog.findViewById(R.id.button2);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
});
The adapter:
public class MyExpandableAdapter extends BaseExpandableListAdapter {
private Activity activity;
private ArrayList<Object> childtems;
private LayoutInflater inflater;
private ArrayList<String> parentItems;
private ArrayList<CheckBox> child;
// constructor
public MyExpandableAdapter(ArrayList<String> parents, ArrayList<Object> childern)
{
this.parentItems = parents;
this.childtems = childern;
}
public void setInflater(LayoutInflater inflater, Activity activity)
{
this.inflater = inflater;
this.activity = activity;
}
@Override
public int getGroupCount() {
return parentItems.size();
}
@Override
public int getChildrenCount(int i) {
return ((ArrayList<CheckBox>) childtems.get(i)).size();
}
@Override
public Object getGroup(int i) {
return null;
}
@Override
public Object getChild(int i, int i1) {
return null;
}
@Override
public long getGroupId(int i) {
return 0;
}
@Override
public long getChildId(int i, int i1) {
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int i, boolean b, View convertView, ViewGroup viewGroup) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_group, null);
}
TextView textView=(TextView)convertView.findViewById(R.id.textView);
textView.setText(parentItems.get(i));
//((TextView) convertView).setChecked(isExpanded);
return convertView;
}
@Override
public View getChildView(int i, int i1, boolean b, View convertView, ViewGroup viewGroup) {
child = (ArrayList<CheckBox>) childtems.get(i);
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item, null);
}
CheckBox cb=(CheckBox)convertView.findViewById(R.id.checkBox);
cb.setText(child.get(i1).getText());
cb.setFocusable(false);
cb.setClickable(false);
return convertView;
}
@Override
public boolean isChildSelectable(int i, int i1) {
return true;
}
}
This way, in the OnChildClickListener, I get the NAME of the component (what's in the CheckBox text) by accessing the corresponding arraylist. But the CheckBox is not checked...so the user doesn't knows the checkbox has been selected.
How can i set the checkbox as clicked, so the user can know his/her selection has been made?
Aucun commentaire:
Enregistrer un commentaire