Expandablelistview 自定义指标不可见

Expandablelistview custom indicator not visible

我有一个带有自定义指示器的可扩展列表视图,但不知为何该指示器没有显示在可扩展列表视图中。

我是不是忽略了什么?非常感谢你帮助我。

编辑:现在一切正常,在正确的代码下方。

custom_arrow.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_empty="true" android:drawable="@drawable/arrow_down_black"/>
   <item android:state_expanded="true" android:drawable="@drawable/arrow_up_black"/>
   <item android:drawable="@drawable/arrow_down_black"/>
</selector>

具有可扩展列表视图的框架布局:

<LinearLayout
    android:id="@+id/expandablelv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/layout_bg"
    android:orientation="vertical">

    <ExpandableListView
        android:transcriptMode="alwaysScroll"
        android:id="@+id/exp"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_marginLeft="5dp">

    </ExpandableListView>
</LinearLayout>

我的代码:

 @Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
//
lv = (ExpandableListView) view.findViewById(R.id.exp);
  lv.setAdapter(new ExpandableListAdapter(groups, children)); 
   lv.setGroupIndicator(this.getResources().getDrawable(R.drawable.custom_arrow));
//
}

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private final LayoutInflater inf;
    private String[] groups;
    private String[][] children;

    public ExpandableListAdapter(String[] groups, String[][] children) {
        this.groups = groups;
        this.children = children;
        inf = LayoutInflater.from(getActivity());
    }

    @Override
    public int getGroupCount() {
        return groups.length;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return children[groupPosition].length;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groups[groupPosition];
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return children[groupPosition][childPosition];
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = inf.inflate(R.layout.child_layout, parent, false);
            holder = new ViewHolder();

            holder.text = (TextView) convertView.findViewById(R.id.textView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text.setText(getChild(groupPosition, childPosition).toString());

        return convertView;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = inf.inflate(R.layout.parent_layout, parent, false);

            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.textView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text.setText(getGroup(groupPosition).toString());

        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    private class ViewHolder {
        TextView text;
    }
}

这对我有用:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_empty="true" android:drawable="@drawable/arrow_down_black"/>
    <item android:state_expanded="true" android:drawable="@drawable/arrow_up_black"/>
    <item android:drawable="@drawable/arrow_down_black"/>
</selector>

可以在this(有点)相关问题中找到更多信息。