我正在开发一个包含可扩展列表视图的应用程序,前两个级别工作正常,但是我想添加第三个级别,我设法通过在项目布局的末尾添加一个列表视图来做到这一点,如下所示:
<?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;
}
});
但该列表从未出现,这可能是什么问题? 如果您需要更多信息,请询问。