gpt4 book ai didi

android - Expandablelistview 自定义指标不可见

转载 作者:行者123 更新时间:2023-11-29 00:13:44 25 4
gpt4 key购买 nike

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

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

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

自定义箭头.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>

带有可扩展 ListView 的框架布局:

<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 中找到更多信息(有点)相关的问题。

关于android - Expandablelistview 自定义指标不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28138679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com