在我的应用程序中,我有一个可扩展的列表视图,我想要使用另一个drawable更改可扩展列表视图上的组箭头,但不显示任何内容。这是我的代码,我该如何解决?
<ExpandableListView
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/expandableListView"
android:groupIndicator="@drawable/group_indicator"/>
group_indicator.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_up"></item>
<item android:state_expanded="true" android:drawable="@drawable/arrow_down"></item>
<item android:drawable="@drawable/arrow_up"></item>
</selector>
ParentActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ParentActivity thisActivity = this;
setContentView(R.layout.backup_list);
ActionBar actionBar = getSherlock().getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.expandableListView);
expListView.setIndicatorBounds(width - GetDipsFromPixel(50), width - GetDipsFromPixel(10));
....
}
public int GetDipsFromPixel(float pixels)
{
// Get the screen's density scale
final float scale = getResources().getDisplayMetrics().density;
// Convert the dps to pixels, based on density scale
return (int) (pixels * scale + 0.5f);
}
有人帮我吗?我真的需要它。
修改
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private ParentActivity parentActivity;
private List<SelectableEntity> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<SelectableEntity>> _listDataChild;
public ExpandableListAdapter(ParentActivity context, List<SelectableEntity> listDataHeader, HashMap<String, List<SelectableEntity>> listChildData) {
this.parentActivity = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public SelectableEntity getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition).title).get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.parentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item2, null);
}
final SelectableEntity child = getChild(groupPosition, childPosition);
TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
txtListChild.setText(child.title);
CheckBox childBox = (CheckBox) convertView.findViewById(R.id.childcheckbox);
childBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
parentActivity.checkParent(child, ((CheckBox) view).isChecked());
}
});
childBox.setChecked(child.state);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition).title)
.size();
}
@Override
public SelectableEntity getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
SelectableEntity header = getGroup(groupPosition);
final LayoutInflater infalInflater = (LayoutInflater) this.parentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) convertView = infalInflater.inflate(R.layout.list_group, null);
TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(header.title);
final TextView textView = (TextView) convertView.findViewById(R.id.lblListHeader);
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.parentcheckbox);
checkBox.setChecked(header.state);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
parentActivity.checkAll(textView.getText().toString(), ((CheckBox) view).isChecked());
}
}
);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}