tutorial studio programacion instalacion espaƱol avanzado android expandablelistview

studio - manual de programacion android



Android ExpandableListView-Buscando un tutorial (3)

Estoy tratando de programar una interfaz de Android que utiliza una lista ampliable en un lado y un fragmento en el otro lado para que pueda cargar diferentes recursos haciendo clic en los elementos secundarios de la lista desplegable. Pero desafortunadamente no puedo encontrar buenos tutoriales sobre esta lista en ninguna parte. Sí, he buscado en las demostraciones de API y he hecho una lista normal con un BaseExpandableListAdapter, pero aun así, entender esa lista es bastante difícil sin un buen tutorial, ¿tiene alguna buena información o información que pueda verificar?


De esta forma puedes manejar eventos:

getExpandableListView().setOnChildClickListener(new OnChildClickListener() { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // your code... } }


Puede encontrar un ejemplo de trabajo de la vista de lista desplegable siguiendo los enlaces:

para hacer clic en el niño, puede manejar de esta manera.

getExpandableListView().setOnChildClickListener(new OnChildClickListener() { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // your code... } });

Espero que esto te ayudará. Gracias..


Crear lista de elementos

List<ParentItem> itemList = new ArrayList<ParentItem>(); ParentItem parent1 = new ParentItem(); parent1.getChildItemList().add(new ChildItem()); parent1.getChildItemList().add(new ChildItem()); parent1.getChildItemList().add(new ChildItem()); ParentItem parent2 = new ParentItem(); parent2.getChildItemList().add(new ChildItem()); parent2.getChildItemList().add(new ChildItem()); parent2.getChildItemList().add(new ChildItem()); itemList.add(parent1); itemList.add(parent2); ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(context, itemList);

Objetos de datos

public class ParentItem { private List<ChildItem> childItemList; public ParentItem() { childItemList = new ArrayList<ChildItem>(); } public List<ChildItem> getChildItemList() { return childItemList; } } public class ChildItem { // filll with your data }

Adaptador

public class ExpandableListViewAdapter extends BaseExpandableListAdapter { private static final class ViewHolder { TextView textLabel; } private final List<ParentItem> itemList; private final LayoutInflater inflater; public ExpandableListViewAdapter(Context context, List<ParentItem> itemList) { this.inflater = LayoutInflater.from(context); this.itemList = itemList; } @Override public ChildItem getChild(int groupPosition, int childPosition) { return itemList.get(groupPosition).getChildItemList().get(childPosition); } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public int getChildrenCount(int groupPosition) { return itemList.get(groupPosition).getChildItemList().size(); } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, final ViewGroup parent) { View resultView = convertView; ViewHolder holder; if (resultView == null) { resultView = inflater.inflate(android.R.layout.test_list_item, null); //TODO change layout id holder = new ViewHolder(); holder.textLabel = (TextView) resultView.findViewById(android.R.id.title); //TODO change view id resultView.setTag(holder); } else { holder = (ViewHolder) resultView.getTag(); } final ChildItem item = getChild(groupPosition, childPosition); holder.textLabel.setText(item.toString()); return resultView; } @Override public ParentItem getGroup(int groupPosition) { return itemList.get(groupPosition); } @Override public int getGroupCount() { return itemList.size(); } @Override public long getGroupId(final int groupPosition) { return groupPosition; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View theConvertView, ViewGroup parent) { View resultView = theConvertView; ViewHolder holder; if (resultView == null) { resultView = inflater.inflate(android.R.layout.test_list_item, null); //TODO change layout id holder = new ViewHolder(); holder.textLabel = (TextView) resultView.findViewById(android.R.id.title); //TODO change view id resultView.setTag(holder); } else { holder = (ViewHolder) resultView.getTag(); } final ParentItem item = getGroup(groupPosition); holder.textLabel.setText(item.toString()); return resultView; } @Override public boolean hasStableIds() { return true; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } }

Te dio

============================== +Parent 1 ============================== -child 1.1 ============================== -child 1.2 ============================== -child 1.3 ============================== +Parent 2 ============================== -child 2.1 ============================== -child 2.2 ============================== -child 2.3 ==============================