请教一下,ExpandableListView无法显示的问题

youyuan1980 2014-02-03 07:23:42
主界面

list=(ExpandableListView)findViewById(R.id.list);
List<String> GroupList=new ArrayList<String>();
List<List<String>> childs = new ArrayList<List<String>>();
GroupList.add("第一项");
GroupList.add("第二项");

List<String> itemList1=new ArrayList<String>();
itemList1.add("第一项第一行");
itemList1.add("第一项第二行");
childs.add(itemList1);

List<String> itemList2=new ArrayList<String>();
itemList2.add("第二项第一行");
itemList2.add("第二项第二行");
childs.add(itemList2);
list.setAdapter(new MyExpandableListAdapter(GroupList,childs,MainActivity.this));


自定义适配器代码
class MyExpandableListAdapter extends BaseExpandableListAdapter
{
private List<String> GroupList=null;
private List<List<String>> childs=null;
private Context mContext=null;
public MyExpandableListAdapter(List<String> groupList,
List<List<String>> childs,Context context) {
super();
GroupList = groupList;
this.childs = childs;
this.mContext=context;
}


@Override
public Object getChild(int groupPosition,
int childPosition) {
// TODO Auto-generated method stub
return childs.get(groupPosition).get(childPosition);
}

@Override
public long getChildId(int groupPosition,
int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}

@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return childs.get(groupPosition).size();
}

@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return GroupList.get(groupPosition);
}

@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return GroupList.size();
}

@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}

@Override
public View getGroupView(int groupPosition,
boolean isExpanded, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView==null)
{
LayoutInflater _Layoutinflater=LayoutInflater.from(mContext);
convertView=_Layoutinflater.inflate(R.layout.groups,null);
TextView grouptext=(TextView)convertView.findViewById(R.id.textGroup);
grouptext.setText(getGroup(groupPosition).toString());
}
return convertView;
}

@Override
public View getChildView(int groupPosition,
int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView==null)
{
LayoutInflater _Layoutinflater=LayoutInflater.from(mContext);
convertView=_Layoutinflater.inflate(R.layout.childs,null);
TextView childtext=(TextView)convertView.findViewById(R.id.textChild);
Log.i("my", getChild(groupPosition, childPosition).toString());
childtext.setText(getChild(groupPosition, childPosition).toString());
}
return convertView;
}

@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}

@Override
public boolean isChildSelectable(int groupPosition,
int childPosition) {
// TODO Auto-generated method stub
return true;
}

};


主界面布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >
<ExpandableListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
/>
</LinearLayout>


组布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="9pt"
android:textColor="#000000"
/>
</LinearLayout>


子布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textChild"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="15sp"
/>
</LinearLayout>



调试下来都有值,在getview里面也有值,就是在主界面上显示不出来,请高手看一下。。
...全文
125 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
youyuan1980 2014-02-04
  • 打赏
  • 举报
回复
在单位试了一下,可以运行的,奇怪了,可能和环境有关系。
youyuan1980 2014-02-04
  • 打赏
  • 举报
回复
顶一下。。请高手解答一下。

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧