Расширяемый трехуровневый ListView - PullRequest
0 голосов
/ 07 января 2019

Я работаю над приложением, которое содержит расширяемый просмотр списка, первые два уровня работают нормально, но я хотел добавить третий уровень, мне удалось это сделать, добавив просмотр списка в конце макета элемента, как показано ниже :

<?xml version="1.0" encoding = "utf-8"?>
<LinearLayout
 ...">

    <RelativeLayout
     ...">

        <ImageView
            android:id="@+id/delete_order_customer"
            ... />

        <TextView
            android:id="@+id/order_customer_name"
            ... />

        <TextView
            android:id="@+id/order_customer_cost"
            .../>

        <ImageView
            android:id="@+id/insert_customer_sandwich_btn"
            ... />

    </RelativeLayout>

    <ListView
        android:id="@+id/customer_sandwich_list"             
        android:visibility="gone"
        ..."/>

</LinearLayout>

и внутри фрагмента я получаю доступ к списку следующим образом:

LayoutInflater layoutInflater = getLayoutInflater();
        View myView = layoutInflater.inflate(R.layout.order_item, null);

        customerSandwichListView = myView.findViewById(R.id.customer_sandwich_list); 

поэтому я прикрепляю OnChildClickListener к расширяемому списку, поэтому, когда пользователь щелкает дочернего элемента, соответствующий список должен отображаться под ним. Я пытаюсь добиться такого поведения с помощью следующего кода:

orderExpandableListView.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {
                //showDialogFragment();
                //Toast.makeText(getContext(), "GP: " + groupPosition + ", CP: " + childPosition, Toast.LENGTH_SHORT).show();
                OrderCustomer currentOrderCustomer = (OrderCustomer) orderExpandableListAdapter
                        .getChild(groupPosition, childPosition);

                ArrayList<CustomerSandwich> customerSandwiches1 = customerSandwiches.get(currentOrderCustomer);

                adapter = new CustomerSandwichListAdapter(getContext(), R.layout.customer_sandwich_item, customerSandwiches1);
                //adapter.add(CustomerSandwich);
                customerSandwichListView.setAdapter(adapter);

                if(customerSandwichListView.getVisibility() == View.GONE)
                    customerSandwichListView.setVisibility(View.VISIBLE);
                else if(customerSandwichListView.getVisibility() == View.VISIBLE)
                    customerSandwichListView.setVisibility(View.GONE);
                return true;
            }
        });

но список никогда не появляется, в чем здесь может быть проблема? если вы хотите больше информации, пожалуйста, спросите.

...