Открыть действие при нажатии на подэлемент в ExpandableListView - PullRequest
0 голосов
/ 15 апреля 2019

У меня есть некоторый исходный код, который позволяет Expandablelistview отображать подпунктов .

Я хотел бы получить несколько советов о том, как вызывать действия при нажатии каждого подэлемента (например, DDB1, DnB2, Digger1, Digger 2 и т. Д.) в родительском списке.

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mExpandingList = findViewById(R.id.expanding_list_main);
    createItems();

}

private void createItems() {
    addItem("Drill and Blast", new String[]{"DnB1", "DnB2", "DnB3", "DnB4"}, R.color.pink, R.drawable.drill);
    addItem("Excavator and Shovel", new String[]{"Digger1", "Digger2", "Digger3", "Digger4"}, R.color.blue, R.drawable.excavator);
    addItem("Dragline", new String[]{"Dragline1", "Dragline2", "Dragline3", "Dragline4"}, R.color.purple, R.drawable.dragline);
    addItem("Haulage", new String[]{"Haulage1", "Haulage2", "Haulage3", "Haulage4"}, R.color.yellow, R.drawable.truck);
    addItem("Dozer push", new String[]{"Dozer1", "Dozer2", "Dozer3", "Dozer4"}, R.color.orange, R.drawable.dozerpush);
    addItem("Safety", new String[]{"Safety1", "Safety2", "Safety3", "Safety4"}, R.color.green, R.drawable.safety);

}

private void addItem(String title, String[] subItems, int colorRes, int iconRes) {
    //Let's create an item with R.layout.expanding_layout
    final ExpandingItem item = mExpandingList.createNewItem(R.layout.expanding_layout);


    //If item creation is successful, let's configure it
    if (item != null) {
        item.setIndicatorColorRes(colorRes);
        item.setIndicatorIconRes(iconRes);

        //It is possible to get any view inside the inflated layout. Let's set the text in the item
        ((TextView) item.findViewById(R.id.title)).setText(title);

        //We can create items in batch.
        item.createSubItems(subItems.length);
        for (int i = 0; i < item.getSubItemsCount(); i++) {
            //Let's get the created sub item by its index
            final View view = item.getSubItemView(i);

            //Let's set some values in
            configureSubItem(item, view, subItems[i]);
        }

    }

}
private void configureSubItem(final ExpandingItem item, final View view, String subTitle) {
    ((TextView) view.findViewById(R.id.sub_title)).setText(subTitle);

}


}
...