如何在打开时隐藏expandableListView组名

问题描述 投票:1回答:1

我在DrawerList中有这个结构:

  • 更多...
  • -宾语
  • -宾语
  • -...隐藏

当它打开时我需要隐藏“更多...”。

在这个部分做:

public class CategoryItemsAdapter extends BaseExpandableListAdapter {
...
public View getChildView(int groupPosition, int childPosition, boolean isExpanded, View view,
                         ViewGroup parent) {
    Link child = (Link) getChild(groupPosition, childPosition);
    LinksGroup group = (LinksGroup) getGroup(groupPosition);

    if (view == null) {
        LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        view = infalInflater.inflate(R.layout.category_item_counter, null);
    }
    TextView tv = (TextView) view.findViewById(R.id.title);
    tv.setText(child.getName().toString());

    if(isExpanded) {
    }
    else {
    }


    return view;
}

public View getGroupView(int groupPosition, boolean isLastChild, View view,
                         ViewGroup parent) {
    LinksGroup group = (LinksGroup) getGroup(groupPosition);

    String groupTitle = getGroup(groupPosition).toString();
    View viewGroup = new FrameLayout(context);

    if (view == null) {
        LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        view = inf.inflate(R.layout.category_item_counter, null);
    }
    TextView tv = (TextView) view.findViewById(R.id.title);

    final float scale = context.getResources().getDisplayMetrics().density;
    int space = (int) (20 * scale + 0.5f);
    int item = (int) (40 * scale + 0.5f);

    if(group.getName() == null) {
        tv.setBackgroundColor(Color.DKGRAY);
        tv.setHeight(space);
        tv.setText("");
    }
    else {
        tv.setBackgroundColor(Color.WHITE);
        tv.setHeight(item);
        tv.setText(group.getName());
    }

    return view;
}
...
}

或者我可以在OnGroupClickListener上执行此操作?

我想了很久。需要帮忙。

android expandablelistview
1个回答
0
投票

好的,我刚添加了这个:

 if(isExpanded) {
   tv.setHeight(0);
   return view;
 }

public View getGroupView(int groupPosition, boolean isExpanded, View view,
                         ViewGroup parent)
© www.soinside.com 2019 - 2024. All rights reserved.