2010-08-05 10 views

Respuesta

20

debe suscribirse a setOnChildClickListener

getExpandableListView().setOnChildClickListener(this); 

e implementar OnChildClickListener

@Override 
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, 
     int childPosition, long id) { 
    // use groupPosition and childPosition to locate the current item in the adapter 
    return true; 
} 
+0

¿Esto se aplica al ejemplo he vinculado? Parece que ese ejemplo no implementa ExpandableListView – user412164

+0

Claro que lo hace, ya que se extiende 'ExpandableListActivity' – Pentium10

+0

Gracias. ¿Sabría usted cuál es la forma correcta de obtener el valor o la "etiqueta" del niño cliqueado? – user412164

1

Debe anular onChildClick en su extensión ExpandableListActivity.

+0

¿cómo obtengo el hijo seleccionado después de anular? – Mikey

2

Se debe especificar la ubicación de los elementos de la lista ampliable como esto

listView.setOnChildClickListener(new OnChildClickListener() 
{ 
    @Override 
    public boolean onChildClick(ExpandableListView parent, View v, int group_position, int child_position, long id) 
    { 
     if(group_position==0 && child_position==0){ 
      TryFragment secondFragment = (TryFragment) SampleActivity.this.getFragmentManager().findFragmentById(R.id.tryFragment); 
      secondFragment.getView().setVisibility(View.VISIBLE); 
     } else if(group_position==2 && child_position==2){ 
      TryFragment secondFragment = (TryFragment) SampleActivity.this.getFragmentManager().findFragmentById(R.id.tryFragment); 
      secondFragment.getView().setVisibility(View.VISIBLE); 
     } 
     return false; 
    } 
}); 
Cuestiones relacionadas