Cómo obtener un elemento de un niño en ExpandableListView?

Tengo método onChildClick en mi aplicación, este mi código

public class listview extends ExpandableListActivity { private static final String NAME = "NAME"; private static final String IS_EVEN = "IS_EVEN"; private ExpandableListAdapter mAdapter; List<Map<String, String>> groupData = new ArrayList<Map<String, String>>(); List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>(); InputStream is; boolean addState = true; boolean addCountry; HashMap<String, String> countryMap = new HashMap<String, String>(); HashMap<String, String> stateMap = new HashMap<String, String>(); int count = 0; int count1 = -1; int count2 = 0; List<String> stateCount = new ArrayList<String>(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Reading data from text file to inout stream is = this.getResources().openRawResource(R.raw.countrystate); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); try { String line = ""; while ((line = reader.readLine()) != null) { String[] strings = line.split("-"); String ctry = strings[0].trim(); String st = strings[1].trim(); /* * loading country and state to two separate hash tables */ if (countryMap.containsValue(ctry)) { addCountry = false; if (!addState) { stateMap.put("state" + count1 + count2, st); count2++; } } else { addCountry = !addCountry; count1++; //adding no. of states for a country to a list stateCount.add("" + count2); if (addCountry) { count2 = 0; countryMap.put("country" + count, ctry); stateMap.put("state" + count1 + count2, st); addState = false; } count2++; count++; } } } catch (Exception e) { } //re-arranging the state count list stateCount.add("" + count2); stateCount.remove(0); for (int i = 0; i < countryMap.size(); i++) { Map<String, String> curGroupMap = new HashMap<String, String>(); groupData.add(curGroupMap); String ctry = countryMap.get("country" + i); curGroupMap.put(NAME, ctry); curGroupMap.put(IS_EVEN, "Country " + i); List<Map<String, String>> children = new ArrayList<Map<String, String>>(); int k = Integer.parseInt(stateCount.get(i)); for (int j = 0; j < k; j++) { Map<String, String> curChildMap = new HashMap<String, String>(); children.add(curChildMap); curChildMap.put(NAME, stateMap.get("state" + i + j)); // curChildMap.put(IS_EVEN, "State " + j); } childData.add(children); } // Set up our adapter mAdapter = new SimpleExpandableListAdapter(this, groupData, android.R.layout.simple_expandable_list_item_1, new String[] { NAME, IS_EVEN }, new int[] { android.R.id.text1, android.R.id.text2 }, childData, android.R.layout.simple_expandable_list_item_2, new String[] { NAME, IS_EVEN }, new int[] { android.R.id.text1, android.R.id.text2 }); setListAdapter(mAdapter); } public boolean onChildClick (ExpandableListView parent, View v, int groupPosition,int childPosition,long id) { System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition+v.toString()); return true; } public List<List<Map<String, String>>> getChildData() { return childData; } } 

Mi método onClick

 public boolean onChildClick (ExpandableListView parent, View v, int groupPosition,int childPosition,long id) { System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition+v.toString()); return true; } 

Quiero obtener la cadena si hice clic en la lista de los niños

Este mi logcat:

 07-18 11:40:54.334: INFO/System.out(1014): Inside onChildClick at groupPosition = 0 Child clicked at position 0android.widget.TwoLineListItem@405337c0 07-18 11:40:56.714: DEBUG/dalvikvm(916): GC_EXPLICIT freed 14K, 53% free 2557K/5379K, external 884K/1038K, paused 111ms 07-18 11:40:58.744: INFO/System.out(1014): Inside onChildClick at groupPosition = 0 Child clicked at position 0android.widget.TwoLineListItem@405337c0 

Quiero obtener datos de la cadena no "TwoLineListItem @ 405337c0", cualquier persona puede ayudarme? Gracias

Utilizar:

 parent.getExpandableListAdapter().getChild(groupPosition, childPosition); 

(Si desea que los datos de un niño, o .getGroup(groupPosition) si desea los datos del grupo) vista en lugar de:

 v.toString() 

prueba esto

 public boolean onChildClick (ExpandableListView parent, View v, int groupPosition,int childPosition,long id) { System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childData.get(groupposition).get(childPosition).get("NAME")); return true; } 

Por alguna razón las respuestas anteriores no funcionó para mí, pero he encontrado una solución aquí abajo

 @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // TODO Auto-generated method stub String message; TextView tx = (TextView) v; message=tx.getText().toString(); return false; } 

A través de este código obtendrá el texto del niño ExpandableListView hecho clic

  • ExpandableListView muestra de Google
  • ¿Es posible cambiar el navegador / motor predeterminado para la vista Web de Android?
  • Android recibe actividad de alojamiento desde una vista
  • Android WebView: bloqueo tras la carga de url
  • Android 3-level-ExpandableListView no mostrar filas sólo en el tercer nivel
  • Visualización preliminar en el grabador de medios android
  • Obtener la vista de los padres desde un diseño
  • Reciclando vistas en vista de desplazamiento
  • Grupos enlazados en ExpandableListView
  • Softkey superposición con el campo EditText
  • ImageView ser un cuadrado con ancho dinámico?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.