当我尝试将可扩展列表插入现有活动(不是从 ExpandalbleListActivity 派生的)时遇到了几个问题。
该列表确实像我的 XML 布局中描述的那样显示,但是当我尝试单击/展开它时它没有反应。
为了测试,我在列表上方插入了一个按钮,它会收到点击。它自己的列表没有说可点击=假。
可扩展列表的代码:
<ExpandableListView
android:id="@+id/h_Zzwa_activity_listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:groupIndicator="@color/transparent" android:clickable="true">
</ExpandableListView>
初始化列表的代码:
this.m_adapter = new HZzwaListAdapter(this, m_requests);
listZzwa = (ExpandableListView) findViewById(R.id.h_Zzwa_activity_listView);
listZzwa.setAdapter(this.m_adapter)
适配器(启动并调用组..)
public class HZzwaListAdapter extends BaseExpandableListAdapter
{
private List<HMyMessage> items;
private Context myContext;
public HZzwaListAdapter(Context context)
{
myContext = context;
}
public HZzwaListAdapter(Context context, List<HMyMessage> items)
{
myContext = context;
this.items = items;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.h_Zzwa_list_subitem,
null);
}
HMyMessage message = items.get(childPosition);
if (message != null)
{
TextView tvPlayerName = (TextView) convertView
.findViewById(R.id.h_Zzwalistitem_info_signText);
tvPlayerName.setText(message.info.getSign());
}
return convertView;
}
@Override
public int getChildrenCount(int groupPosition)
{
return 1;
}
@Override
public Object getGroup(int groupPosition)
{
return null;
}
@Override
public int getGroupCount()
{
return items.size();
}
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater
.inflate(R.layout.h_machching_list_item, null);
}
// Get item and set it into the view
HMyMessage plan = (HMyMessage) items.get(groupPosition);
if (plan != null)
{
TextView pname = (TextView) convertView
.findViewById(R.id.h_Zzwalistitem_pname);
TextView pF = (TextView) convertView
.findViewById(R.id.h_Zzwalistitem_pText);
if (pname != null)
{
pname.setText(plan.requester.getName());
}
if (pF != null)
{
pF.setText(plan.p + " unit ");
}
}
return convertView;
}
@Override
public boolean hasStableIds()
{
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return true;
}
@Override
public Object getChild(int groupPosition, int childPosition)
{
// TODO Auto-generated method stub
return null;
}
@Override
public long getChildId(int groupPosition, int childPosition)
{
// TODO Auto-generated method stub
return 0;
}
}
即使我为 click 或 listItemClick 事件设置了一个侦听器,也没有任何反应。
为什么?对于通常的列表,同样的事情非常有效:/
谢谢