我使用具有自定义父级和子级布局的简单可扩展基本适配器实现了可扩展列表视图。它在Galaxy Ace中工作正常。列表视图展开并显示子布局。当我在4.0.3上运行时,可扩展列表视图不会扩展,但是在单击组视图时,视图会突出显示
适配器类
public NotificationAdapter(SherlockFragmentActivity activity,ArrayList<NotificationParent> listData)
{
this.activity = activity;
parentList = (ArrayList<NotificationParent>) listData;
Log.e("", "In constrictor" +parentList.get(0).child.size());
}
@Override
public Object getChild(int arg0, int childPosition)
{
// TODO Auto-generated method stub
return null;
}
@Override
public long getChildId(int arg0, int childPosition)
{
// TODO Auto-generated method stub
return childPosition;
}
@Override
public View getChildView(int childPosition, int arg1, boolean arg2, View childView,
ViewGroup viewGroup)
{
// TODO Auto-generated method stub
if ( childView == null)
{
childView = activity.getLayoutInflater().inflate(R.layout.child, viewGroup,false);
}
TextView childDescription = (TextView) childView.findViewById(R.id.not_summary);
TextView action1 = (TextView) childView.findViewById(R.id.not_actions);
TextView action2 = (TextView) childView.findViewById(R.id.not_actions1);
if(childList!=null)
{
NotificationChildren child = childList.get(0);
childDescription.setText(child.childDescription);
action1.setText(child.action1);
action2.setText(child.action2);
}
else
Log.e("", "Child List Null");
action1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
Toast.makeText(activity, "Selected Action1", Toast.LENGTH_LONG).show();
}
});
action2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
Toast.makeText(activity, "Selected Action2", Toast.LENGTH_LONG).show();
}
});
return childView;
}
@Override
public int getChildrenCount(int childpos)
{
// TODO Auto-generated method stub
return childList.size();
}
@Override
public Object getGroup(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getGroupCount()
{
// TODO Auto-generated method stub
return parentList.size();
}
@Override
public long getGroupId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getGroupView(int position, boolean arg1, View view, ViewGroup viewGroup)
{
// TODO Auto-generated method stub
parentPosition =position;
if (view == null)
{
view = activity.getLayoutInflater().inflate(R.layout.grouplist, viewGroup,false);
}
TextView description = (TextView) view.findViewById(R.id.tv_notifi);
TextView notifiDate = (TextView) view.findViewById(R.id.tv1_notifi);
NotificationParent parent = parentList.get(position);
description.setText(parent.description);
notifiDate.setText(parent.notificationDate);
description.setFocusable(false);
notifiDate.setFocusable(false);
return view;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
// TODO Auto-generated method stub
return true;
}
调用适配器的方法
private void createNotificationView()
{
exView = (ExpandableListView) getView().findViewById(R.id.ex_notifi);
ArrayList<NotificationParent> parentList = new ArrayList<NotificationParent>();
List<NotificationChildren> childrenList = new ArrayList<NotificationChildren>();
//getting current time
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat(" HH:mm:ss");
String formattedDate = df.format(c.getTime());
NotificationChildren children = new NotificationChildren();
children.childDescription = getString(R.string.child_not);
children.action1 = "ViewBill";
children.action2 = "PayBill";
childrenList.add(children);
for(int i = 0 ; i < 3 ; i ++)
{
NotificationParent parent = new NotificationParent();
parent.description = getString(R.string.not1);
parent.notificationDate = formattedDate;
parent.child = childrenList;
parentList.add(parent);
}
Log.e("", "Before new adapter");
NotificationAdapter adapter = new NotificationAdapter(getSherlockActivity(), parentList);
Log.e("", "Before calling base adapter");
exView.setAdapter(adapter);