2016-10-14 1 views
0

J'ai une liste extensible, dans l'élément enfant, j'ai ajouté quelques EditText, checkbox et spinner. Ceux-ci sont créés et affichés correctement. EditText et Spinner supplémentaires sont affichés une fois Checkbox est cochée, Puis l'utilisateur peut ajouter du texte et sélectionner la valeur de spinner. Je veux récupérer les valeurs de ces vues supplémentaires (edittext, Spinner, CheckBox) pour chaque élément enfant. Cliquez sur Enregistrer pour parcourir tous les éléments et récupérer les valeurs dans ces champs editText, Spinner et checkBox. Actuellement, j'utilise le code ci-dessous, mais après avoir cliqué sur enregistrer, il renvoie toujours les valeurs associées au dernier élément enfant. S'il vous plaît laissez-moi savoir si plus d'informations sont nécessaires concernant cette question. ExpandableList ScreenShotAndroid: Comment itérer à travers les vues d'un expandableList

MainActivity-

public class MainActivity extends AppCompatActivity { 
ExpandableListAdapter listAdapter; 
ExpandableListView expListView; 
List<String> listDataHeader; 
HashMap<String, List<String>> listDataChild; 

Button save; 
Button cancel; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 

save = (Button) findViewById(R.id.save); 
// get the listview 
expListView = (ExpandableListView) findViewById(R.id.lvExp); 

// preparing list data 
prepareListData(); 

listAdapter = new ExpandableListAdapter(getApplicationContext(), listDataHeader, listDataChild); 

// setting list adapter 
expListView.setAdapter(listAdapter); 

expListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); 

save.setOnClickListener(new Button.OnClickListener() { 
    public void onClick(View v) { 
     System.out.println("Save clicked"); 
     for(int i = 0; i < listAdapter.getGroupCount();i++) { 

      for (int k = 0; k < listAdapter.getChildrenCount(i); k++) { 

       String temp = listAdapter.recollect(i,k); 
       System.out.println("For i="+i+" and k="+k+" string value is="+temp); 
      } 
     } 
    } 
}); 



} 



/* 
* Preparing the list data 
*/ 
private void prepareListData() { 
listDataHeader = new ArrayList<String>(); 
listDataChild = new HashMap<String, List<String>>(); 
// Adding child data 
listDataHeader.add("Nokia"); 
listDataHeader.add("Apple"); 
listDataHeader.add("Samsung"); 

// Adding child data 
List<String> nokia = new ArrayList<String>(); 
nokia.add("Nokia1"); 
nokia.add("Nokia2"); 


List<String> apple = new ArrayList<String>(); 
apple.add("Apple1"); 
apple.add("Apple2"); 


List<String> samsung = new ArrayList<String>(); 
samsung.add("Samsung1"); 
samsung.add("Samsung2"); 

listDataChild.put(listDataHeader.get(0), nokia); // Header, Child data 
listDataChild.put(listDataHeader.get(1), apple); 
listDataChild.put(listDataHeader.get(2), samsung); 
} 
} 

MainLayout-

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="dhritiapps.temp.MainActivity"> 
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="60dp" 
android:id="@+id/lin" 
android:orientation="horizontal"> 
<Button 
android:layout_width="0dp" 
android:layout_height="50dp" 
android:layout_weight="1" 
android:id="@+id/can" 
android:text="Cancel"/> 
<Button 
android:layout_width="0dp" 
android:layout_height="50dp" 
android:layout_weight="1" 
android:id="@+id/save" 
android:text="Save"/> 
</LinearLayout> 
<ExpandableListView 
android:layout_marginTop="10dp" 
android:id="@+id/lvExp" 
android:layout_below="@+id/lin" 
android:layout_height="match_parent" 
android:layout_width="match_parent"/> 
</RelativeLayout> 

ExpandableListAdapter-

public class ExpandableListAdapter extends BaseExpandableListAdapter { 

private Context _context; 
private List<String> _listDataHeader; // header titles 
// child data in format of header title, child title 
private HashMap<String, List<String>> _listDataChild; 
// private final HashMap<String, String, String> mCheckedItems; 
String cat, item, quty, units, notes; 
EditText qty; 
EditText note; 
Spinner unit; 
ArrayList <String> ss=new ArrayList<>(); 

public ExpandableListAdapter(Context context, List<String> listDataHeader, 
HashMap<String, List<String>> listChildData) { 
this._context = context; 
this._listDataHeader = listDataHeader; 
this._listDataChild = listChildData; 

@Override 
public Object getChild(int groupPosition, int childPosititon) { 
return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
.get(childPosititon); 
} 

@Override 
public long getChildId(int groupPosition, int childPosition) { 
return childPosition; 
} 

@Override 
public View getChildView(final int groupPosition, final int childPosition, 
boolean isLastChild, View convertView, ViewGroup parent) { 

final String childText = (String) getChild(groupPosition, childPosition); 

if (convertView == null) { 
LayoutInflater infalInflater = (LayoutInflater) this._context 
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
convertView = infalInflater.inflate(R.layout.list_item, null); 
} 

TextView txtListChild = (TextView) convertView 
.findViewById(R.id.lblListItem); 

final LinearLayout mm = (LinearLayout) convertView.findViewById(R.id.entries); 
qty = (EditText) convertView.findViewById(R.id.qty); 
note = (EditText) convertView.findViewById(R.id.note); 
unit = (Spinner) convertView.findViewById(R.id.unit); 
final CheckBox cb = (CheckBox) convertView.findViewById(R.id.cb); 

final int grp = groupPosition; 

cb.setOnClickListener(new View.OnClickListener() { 

public void onClick(View v) { 

final CheckBox cb = (CheckBox) v; 

if (cb.isChecked()) { 
mm.setVisibility(View.VISIBLE); 
} else { 
mm.setVisibility(View.GONE); 

} 
System.out.println(ss); 
} 
}); 

txtListChild.setText(childText); 

return convertView; 
} 

public String recollect(int grp, int ch) { 
cat = getGroup(grp).toString(); 
item = getChild(grp, ch).toString(); 
quty = qty.getText().toString(); 
units = unit.getSelectedItem().toString(); 
notes = note.getText().toString(); 

System.out.println("cat="+cat+"; item="+item+"; qty="+quty+"; unit="+units+"; note="+notes); 
return cat+";"+item+";"+quty+";"+units+";"+notes+"_"; 
} 

@Override 
public int getChildrenCount(int groupPosition) { 
return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
.size(); 
} 

@Override 
public Object getGroup(int groupPosition) { 
return this._listDataHeader.get(groupPosition); 
} 

@Override 
public int getGroupCount() { 
return this._listDataHeader.size(); 
} 

@Override 
public long getGroupId(int groupPosition) { 
return groupPosition; 
} 

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, 
View convertView, ViewGroup parent) { 
String headerTitle = (String) getGroup(groupPosition); 
if (convertView == null) { 
LayoutInflater infalInflater = (LayoutInflater) this._context 
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
convertView = infalInflater.inflate(R.layout.list_group, null); 
} 
TextView lblListHeader = (TextView) convertView 
.findViewById(R.id.lblListHeader); 

lblListHeader.setTypeface(null, Typeface.BOLD); 
lblListHeader.setText(headerTitle); 

return convertView; 
} 

@Override 
public boolean hasStableIds() { 
return false; 
} 

@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
return true; 
} 


} 

list_Group.xml-

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:padding="8dp" 
android:background="#000000">  

<TextView 
android:id="@+id/lblListHeader" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:paddingLeft="2dp" 
android:textSize="17dp" 
android:textColor="#f9f93d" /> 

</LinearLayout> 

list_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="55dip" 
android:orientation="vertical" 
android:background="#ef8d8d"> 

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:paddingLeft="5dp" 
android:layout_weight="1" 
> 
<TextView 
android:id="@+id/lblListItem" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textSize="17dip" 
android:paddingTop="5dp" 
android:paddingBottom="5dp" 
android:textColor="#ff0000" 
android:layout_weight="5"/> 
<CheckBox 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/cb" 
android:checked="false" 
android:layout_weight="1"/> 
</LinearLayout> 


<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="40dp" 
android:id="@+id/entries" 
android:orientation="horizontal" 
android:paddingLeft="8dp" 
android:visibility="gone" 
android:paddingBottom="2dp" 
android:layout_weight="1"> 
<EditText 
android:id="@+id/qty" 
android:layout_width="0dp" 
android:layout_height="30dp" 
android:hint="Qunatity" 
android:layout_weight="1" 
android:background="#12f212" 
android:layout_margin="3dp" 
android:textColor="#700a55" 
android:inputType="numberDecimal" 
android:maxLength="8" 
android:textSize="12dip"/> 
<Spinner 
android:id="@+id/unit" 
android:layout_width="0dp" 
android:layout_height="30dp" 
android:layout_weight="1" 
android:entries="@array/units" 
android:background="#12f212" 
android:layout_margin="3dp" 
android:textColor="#700a55" 
/> 
<EditText 
android:id="@+id/note" 
android:layout_width="0dp" 
android:layout_height="30dp" 
android:hint="Note" 
android:layout_weight="4" 
android:background="#12f212" 
android:layout_margin="3dp" 
android:textColor="#700a55" 
android:textSize="12dip" 
android:maxLength="50"/> 
</LinearLayout> 

</LinearLayout> 

Après avoir cliqué sur enregistrer, ce que je suis getting-

System.out: For i=0 and k=0 string value is=Nokia;Nokia1;2;C;Note for Samsung2_ 
System.out: For i=0 and k=1 string value is=Nokia;Nokia2;2;C;Note for Samsung2_ 
System.out: For i=1 and k=0 string value is=Apple;Apple1;2;C;Note for Samsung2_ 
System.out: For i=1 and k=1 string value is=Apple;Apple2;2;C;Note for Samsung2_ 
System.out: For i=2 and k=0 string value is=Samsung;Samsung1;2;C;Note for Samsung2_ 
System.out: For i=2 and k=1 string value is=Samsung;Samsung2;2;C;Note for Samsung2_ 

Bien qu'il aurait été comme this-

System.out: For i=0 and k=0 string value is=Nokia;Nokia1;123;A;Note for Note for Nokia1 
System.out: For i=0 and k=1 string value is=Nokia;Nokia2;;; 
System.out: For i=1 and k=0 string value is=Apple;Apple1;;; 
System.out: For i=1 and k=1 string value is=Apple;Apple2;;; 
System.out: For i=2 and k=0 string value is=Samsung;Samsung1;;; 
System.out: For i=2 and k=1 string value is=Samsung;Samsung2;2;C;Note for Samsung2_ 
+0

Partagez @ array/unités ou n'importe ce que c'est? –

+0

Impossible d'obtenir votre point de vue que vous partagez –

+0

unités de tableau ont seulement 3 valeurs A, B C. A B C

Répondre

1

Ajouter nouvelle classe CustomChilds

package stack.buy.com.stackdemos; 

/** 
* Created by Desktop - Ganesh on 10/14/2016. 
*/ 
public class CustomChilds { 
String Quntity; 
String Unit; 
String Note; 
String GroupName; 

public String getQuntity() { 
    return Quntity; 
} 

public void setQuntity(String quntity) { 
    Quntity = quntity; 
} 

public String getUnit() { 
    return Unit; 
} 

public void setUnit(String unit) { 
    Unit = unit; 
} 

public String getNote() { 
    return Note; 
} 

public void setNote(String note) { 
    Note = note; 
} 

public String getGroupName() { 
    return GroupName; 
} 

public void setGroupName(String groupName) { 
    GroupName = groupName; 
} 

public CustomChilds(String quntity, String unit, String note, String groupName) { 
    Quntity = quntity; 
    Unit = unit; 
    Note = note; 
    GroupName = groupName; 
} 

public CustomChilds() { 
} 
} 

Adaptateur:

public class ExpandableListAdapter extends BaseExpandableListAdapter { 

private Context _context; 
private List<String> _listDataHeader; // header titles 
// child data in format of header title, child title 
private HashMap<String, List<CustomChilds>> _listDataChild; 
// private final HashMap<String, String, String> mCheckedItems; 
String cat, item, quty, units, notes; 

ArrayList<String> ss = new ArrayList<>(); 

public ExpandableListAdapter(Context context, List<String> listDataHeader, 
          HashMap<String, List<CustomChilds>> listChildData) { 
    this._context = context; 
    this._listDataHeader = listDataHeader; 
    this._listDataChild = listChildData; 
} 
    @Override 
    public CustomChilds getChild(int groupPosition, int childPosititon){ 
     return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
       .get(childPosititon); 
    } 

    @Override 
    public long getChildId (int groupPosition, int childPosition){ 
     return childPosition; 
    } 

    @Override 
    public View getChildView (final int groupPosition, final int childPosition, 
    boolean isLastChild, View convertView, ViewGroup parent){ 

     final CustomChilds childText =getChild(groupPosition, childPosition); 
     final ViewHolder holder; 

     View row = convertView; 
     if (row == null) { 
      LayoutInflater inflater = (LayoutInflater) this._context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      row = inflater.inflate(R.layout.list_item, parent, false); 
      holder = new ViewHolder(); 
      holder.mm = (LinearLayout) row.findViewById(R.id.entries); 
      holder.qty = (EditText) row.findViewById(R.id.qty1); 
      holder.note = (EditText) row.findViewById(R.id.note); 
      holder.unit = (Spinner) row.findViewById(R.id.unit); 
      holder.cb = (CheckBox) row.findViewById(R.id.cb); 
      holder.txtListChild = (TextView) row 
        .findViewById(R.id.lblListItem); 
      row.setTag(holder); 
     } 

     else { 
      // view already exists, get the holder instance from the view 
      holder = (ViewHolder) row.getTag(); 
     } 

     List<CustomChilds> temp = _listDataChild.get(this._listDataHeader.get(groupPosition)); 
     temp.set(childPosition,new CustomChilds(holder.qty.getText().toString(),holder.unit.getSelectedItem().toString(),holder.note.getText().toString(),childText.GroupName)); 

     final int grp = groupPosition; 

     holder.cb.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 

       final CheckBox cb = (CheckBox) v; 

       if (cb.isChecked()) { 
        holder.mm.setVisibility(View.VISIBLE); 
       } else { 
        holder.mm.setVisibility(View.GONE); 

       } 
       System.out.println(ss); 
      } 
     }); 

     holder.txtListChild.setText(childText.getGroupName()); 

     return row; 
    } 



@Override 
public int getChildrenCount(int groupPosition) { 
    return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
      .size(); 
} 

@Override 
public Object getGroup(int groupPosition) { 
    return this._listDataHeader.get(groupPosition); 
} 

@Override 
public int getGroupCount() { 
    return this._listDataHeader.size(); 
} 

@Override 
public long getGroupId(int groupPosition) { 
    return groupPosition; 
} 

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, 
         View convertView, ViewGroup parent) { 
    String headerTitle = (String) getGroup(groupPosition); 
    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater) this._context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.list_group, null); 
    } 
    TextView lblListHeader = (TextView) convertView 
      .findViewById(R.id.lblListHeader); 

    lblListHeader.setTypeface(null, Typeface.BOLD); 
    lblListHeader.setText(headerTitle); 

    return convertView; 
} 

@Override 
public boolean hasStableIds() { 
    return false; 
} 

@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    return true; 
} 



// somewhere else in your class definition 
static class ViewHolder { 
    EditText qty; 
    EditText note; 
    Spinner unit; 
    LinearLayout mm; 
    CheckBox cb; 
    TextView txtListChild; 
} 
} 

MainActivity

public class MainActivity extends AppCompatActivity { 

ExpandableListAdapter listAdapter; 
ExpandableListView expListView; 
List<String> listDataHeader; 
HashMap<String, List<CustomChilds>> listDataChild; 

Button save; 
Button cancel; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    save = (Button) findViewById(R.id.save); 


    listAdapter = new ExpandableListAdapter(getApplicationContext(), listDataHeader, listDataChild); 



    expListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); 

    save.setOnClickListener(new Button.OnClickListener() { 
     public void onClick(View v) { 
      System.out.println("Save clicked"); 
      for(int i = 0; i < listAdapter.getGroupCount();i++) { 
       for (int k = 0; k < listAdapter.getChildrenCount(i); k++) { 


        CustomChilds child = listAdapter.getChild(i, k); 
        String unit=child.getUnit(); 
        String note=child.getNote(); 
        String qut=child.getQuntity(); 

        System.out.println("For i="+i+" and k="+k+" string value is="+child.getNote()); 
       } 
      } 
     } 
    }); 



} 



private void prepareListData() { 
    listDataHeader = new ArrayList<String>(); 
    listDataChild = new HashMap<String, List<CustomChilds>>(); 
    listDataHeader.add("Nokia"); 
    listDataHeader.add("Apple"); 
    listDataHeader.add("Samsung"); 

    List<CustomChilds> nokia = new ArrayList<CustomChilds>(); 
    nokia.add(new CustomChilds("","","","Nokia1")); 
    nokia.add(new CustomChilds("","","","Nokia2")); 


    List<CustomChilds> apple = new ArrayList<CustomChilds>(); 
    apple.add(new CustomChilds("","","","Apple1")); 
    apple.add(new CustomChilds("","","","Apple2")); 



    List<CustomChilds> samsung = new ArrayList<CustomChilds>(); 
    samsung.add(new CustomChilds("","","","Samsung1")); 
    samsung.add(new CustomChilds("","","","Samsung2")); 

    listDataChild.put(listDataHeader.get(0), nokia); // Header, Child data 
    listDataChild.put(listDataHeader.get(1), apple); 
    listDataChild.put(listDataHeader.get(2), samsung); 
} 
} 

Unité Get, quantité et la note onClick

save.setOnClickListener(new Button.OnClickListener() { 
    public void onClick(View v) { 
     System.out.println("Save clicked"); 
     for(int i = 0; i < listAdapter.getGroupCount();i++) { 
      for (int k = 0; k < listAdapter.getChildrenCount(i); k++) { 


       CustomChilds child = listAdapter.getChild(i, k); 
       String unit=child.getUnit(); 
       String note=child.getNote(); 
       String qut=child.getQuntity(); 

       System.out.println("For i="+i+" and k="+k+" string value is="+child.getNote()); 
      } 
     } 
    } 
}); 
+0

Ceci est le code final .. –

+0

Merci beaucoup @Ganesh Pokale. Ça marche maintenant –

0

vous utilisez le même texte d'édition afin qu'il ne vous donne que les dernières valeurs à la place, ajoutez un écouteur textchange sur le texte d'édition et dans la méthode onTextChanged() ajoutez des valeurs de ce modifiez le texte dans une liste comme ceci: Ajoutez également une balise avec la position et utilisez la balise pour récupérer la valeur de la liste.

myEditText1.addTextChangedListener (nouveau GenericTextWatcher (myEditText1));

myEditText1.setTag ("theFirstEditTextAtPos:" + position);

private class GenericTextWatcher implements TextWatcher{ 

     private View view; 
     private GenericTextWatcher(View view) { 
      this.view = view; 
     } 

     public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} 
     public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} 

     public void afterTextChanged(Editable editable) { 

      String text = editable.toString(); 
      //save the value for the given tag : 
      MyResultAdapter.this.textValues.put(view.getTag(), editable.toString()); 
     } 
    } 

    //you can implement a method like this one for each EditText with the list position as parameter : 
    public String getValueFromFirstEditText(int position){ 
      //here you need to recreate the id for the first editText 
     String result = textValues.get("theFirstEditTextAtPos:"+position); 
     if(result ==null) 
       result = "default value"; 

     return result; 
    } 


} 
0

Essayez cette

save.setOnClickListener(new Button.OnClickListener() { 
     public void onClick(View v) { 
      System.out.println("Save clicked"); 
      for(int i = 0; i < listAdapter.getGroupCount();i++) { 
       String group = listAdapter.getGroup(i).toString(); 
       for (int k = 0; k < listAdapter.getChildrenCount(i); k++) { 


        String child = listAdapter.getChild(i, k).toString();; 

        System.out.println("For i="+i+" and k="+k+" string value is="+child); 
       } 
      } 
     } 
    }); 

Trace de la pile:

10-14 16:19:38.877 20206-20206/stack.buy.com.stackdemos I/System.out: For 
i=0 and k=0 string value is=Nokia1 
10-14 16:19:41.395 20206-20206/stack.buy.com.stackdemos I/System.out: For 
i=0 and k=1 string value is=Nokia2 
10-14 16:19:45.015 20206-20206/stack.buy.com.stackdemos I/System.out: For i 
i=1 and k=0 string value is=Apple1 
10-14 16:19:47.663 20206-20206/stack.buy.com.stackdemos I/System.out: For 
i=1 and k=1 string value is=Apple2 
10-14 16:19:50.968 20206-20206/stack.buy.com.stackdemos I/System.out: For 
i=2 and k=0 string value is=Samsung1 
10-14 16:19:51.957 20206-20206/stack.buy.com.stackdemos I/System.out: For 
i=2 and k=1 string value is=Samsung2 

également pour des vues personnalisées stratégie ViewHolder est bonne

public class ExpandableListAdapter extends BaseExpandableListAdapter { 

private Context _context; 
private List<String> _listDataHeader; // header titles 
// child data in format of header title, child title 
private HashMap<String, List<String>> _listDataChild; 
// private final HashMap<String, String, String> mCheckedItems; 
String cat, item, quty, units, notes; 

ArrayList<String> ss = new ArrayList<>(); 

public ExpandableListAdapter(Context context, List<String> listDataHeader, 
          HashMap<String, List<String>> listChildData) { 
    this._context = context; 
    this._listDataHeader = listDataHeader; 
    this._listDataChild = listChildData; 
} 
    @Override 
    public Object getChild(int groupPosition, int childPosititon){ 
     return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
       .get(childPosititon); 
    } 

    @Override 
    public long getChildId (int groupPosition, int childPosition){ 
     return childPosition; 
    } 

    @Override 
    public View getChildView (final int groupPosition, final int childPosition, 
    boolean isLastChild, View convertView, ViewGroup parent){ 

     final String childText = (String) getChild(groupPosition, childPosition); 
     final ViewHolder holder; 

     View row = convertView; 
     if (row == null) { 
      LayoutInflater inflater = (LayoutInflater) this._context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      row = inflater.inflate(R.layout.list_item, parent, false); 
      holder = new ViewHolder(); 
      holder.mm = (LinearLayout) row.findViewById(R.id.entries); 
      holder.qty = (EditText) row.findViewById(R.id.qty1); 
      holder.note = (EditText) row.findViewById(R.id.note); 
      holder.unit = (Spinner) row.findViewById(R.id.unit); 
      holder.cb = (CheckBox) row.findViewById(R.id.cb); 
      holder.txtListChild = (TextView) row 
        .findViewById(R.id.lblListItem); 
      row.setTag(holder); 
     } 

     else { 
      // view already exists, get the holder instance from the view 
      holder = (ViewHolder) row.getTag(); 
     } 



     final int grp = groupPosition; 

     holder.cb.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 

       final CheckBox cb = (CheckBox) v; 

       if (cb.isChecked()) { 
        holder.mm.setVisibility(View.VISIBLE); 
       } else { 
        holder.mm.setVisibility(View.GONE); 

       } 
       System.out.println(ss); 
      } 
     }); 

     holder.txtListChild.setText(childText); 

     return row; 
    } 

    /* public String recollect(int grp, int ch) { 
    cat = getGroup(grp).toString(); 
    item = getChild(grp, ch).toString(); 
    quty = qty.getText().toString(); 
    units = unit.getSelectedItem().toString(); 
     notes = note.getText().toString(); 

     System.out.println("cat=" + cat + "; item=" + item + "; qty=" + quty +       "; unit=" + units + "; note=" + notes); 
    return cat + ";" + item + ";" + quty + ";" + units + ";" + notes + "_"; 
}*/ 

@Override 
public int getChildrenCount(int groupPosition) { 
    return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
      .size(); 
} 

@Override 
public Object getGroup(int groupPosition) { 
    return this._listDataHeader.get(groupPosition); 
} 

@Override 
public int getGroupCount() { 
    return this._listDataHeader.size(); 
} 

@Override 
public long getGroupId(int groupPosition) { 
    return groupPosition; 
} 

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, 
         View convertView, ViewGroup parent) { 
    String headerTitle = (String) getGroup(groupPosition); 
    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater) this._context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.list_group, null); 
    } 
    TextView lblListHeader = (TextView) convertView 
      .findViewById(R.id.lblListHeader); 

    lblListHeader.setTypeface(null, Typeface.BOLD); 
    lblListHeader.setText(headerTitle); 

    return convertView; 
} 

@Override 
public boolean hasStableIds() { 
    return false; 
} 

@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    return true; 
} 



// somewhere else in your class definition 
static class ViewHolder { 
    EditText qty; 
    EditText note; 
    Spinner unit; 
    LinearLayout mm; 
    CheckBox cb; 
    TextView txtListChild; 
} 
} 

Comme, onChildClick si vous voulez vue en cours, puis yo u peut accéder comme ceci:

EditText note= (EditText) v.findViewById(R.id.note); 
String value = tv.getText().toString(); 
+0

Merci pour la réponse détaillée. peut-être que je n'ai pas compris correctement. Comment obtenir les valeurs of- holder.qty, holder.note, holder.unit, holder.cb. Valeur de holder.txtListChild, j'ai pu obtenir correctement. –