我正在尝试做 Expandablelistview。但它没有扩大父视图..
这是我第一次尝试做 Expandablelistview。请帮我解决这个错误。
当我点击父级时,展开不起作用。怎么做。
下面是我的代码
public class WorkDetailView extends Activity {
private ListView listviewDialog;
private ExpandableListView detaillistView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detaillistview);
detaillistView = (ExpandableListView) findViewById(R.id.detailListview);
detaillistView.setDividerHeight(1);
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
width = metrics.widthPixels;
detaillistView.setIndicatorBounds(width - GetDipsFromPixel(40), width - GetDipsFromPixel(5));
dataAdapter = new WorkDetailAdapter(WorkDetailView.this, sampleDetailsArray);
detaillistView.setAdapter(dataAdapter);
dataAdapter.notifyDataSetChanged();
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 + 20f);
}
}
public class WorkDetailAdapter extends BaseExpandableListAdapter {
private LayoutInflater mInflater;
private ArrayList<PatientSampleDetails> sampleDetailsArray;
public WorkDetailAdapter(Activity activity, ArrayList<PatientSampleDetails> sampleDetailsArray) {
this.sampleDetailsArray = sampleDetailsArray;
this.activity = activity;
mInflater = LayoutInflater.from(activity);
}
public void setInflater(LayoutInflater mInflater) {
this.minflater = mInflater;
}
static class ViewHolder {
public ImageView imageView1;
private TextView volumetext, textViewDateTime, textViewOrderNo;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return sampleDetailsArray.get(childPosition);
}
@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) {
final ViewHolder holder = new ViewHolder();
if (convertView == null) {
convertView = mInflater.inflate(R.layout.detaillistrowview, null);
}
convertView.setTag(holder);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return sampleDetailsArray.size();
}
@Override
public int getGroupCount() {
return sampleDetailsArray.size();
}
@Override
public Object getGroup(int groupPosition) {
return sampleDetailsArray.get(groupPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final ViewHolder holder = new ViewHolder();
if (convertView == null) {
convertView = mInflater.inflate(R.layout.getgroupviewdetail, null);
}
CheckBox checkBoxGroup = (CheckBox)convertView.findViewById(R.id.checkBoxGroup);
checkBoxGroup.setChecked(true);
holder.textViewOrderNo = (TextView) convertView.findViewById(R.id.textViewOrderNo);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
Log.i("eeeeeeeeeee", "click");
return true;
}
@Override
public boolean areAllItemsEnabled()
{
return true;
}
}