Android ExpandableListView运行不正常

Android ExpandableListView运行不正常,android,listview,android-listview,expandablelistview,android-adapter,Android,Listview,Android Listview,Expandablelistview,Android Adapter,我的问题是:我花了几个小时试图让一个可扩展的ListView工作。我终于做到了。然后,我尝试将此代码填充到需要此ListView的现有应用程序中。现在它不再工作了。ListView没有真正展开(子项=项)也没有显示。你知道哪里出了问题吗? 我试图清理代码并删除活动中与此ExpandableListView无关的部分。这就是它看起来的样子: (提前非常感谢您的帮助) 公共类ExpandableAdapter扩展了BaseExpandableListAdapter{ 私人名单; 私有上下文ctx;

我的问题是:我花了几个小时试图让一个可扩展的ListView工作。我终于做到了。然后,我尝试将此代码填充到需要此ListView的现有应用程序中。现在它不再工作了。ListView没有真正展开(子项=项)也没有显示。你知道哪里出了问题吗? 我试图清理代码并删除活动中与此ExpandableListView无关的部分。这就是它看起来的样子: (提前非常感谢您的帮助)

公共类ExpandableAdapter扩展了BaseExpandableListAdapter{
私人名单;
私有上下文ctx;
新GraveActivity应用程序;
公共可扩展适配器(列表catList、上下文ctx、NewGraveActivity应用程序){
this.catList=catList;
this.ctx=ctx;
this.app=app;
}
@凌驾
公共对象getChild(int-groupPosition,int-childPosition){
返回catList.get(groupPosition.getItemList().get(childPosition);
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回catList.get(groupPosition).getItemList().get(childPosition).hashCode();
}
@凌驾
公共视图getChildView(最终int-groupPosition、int-childPosition、,
布尔值isLastChild、视图转换视图、视图组父级){
视图v=转换视图;
如果(v==null){
LayoutInflater充气器=(LayoutInflater)ctx.getSystemService
(上下文、布局、充气机和服务);
v=充气机。充气(R.layout.item_布局,父项,false);
}
CheckBox itemCheck=(CheckBox)v.findviewbyd(R.id.itemCheck);
TextView itemName=(TextView)v.findviewbyd(R.id.itemName);
if(app.selected.containsKey((groupPosition))==true)
itemCheck.setChecked(true);
其他的
itemCheck.setChecked(false);
Category child=catList.get(groupPosition).getItemList().get(childPosition);
itemName.setText(child.getName());
setOnCheckedChangeListener(新的CheckListener(childPosition,app));
返回v;
}
@凌驾
公共整数getChildrenCount(整数组位置){
int size=catList.get(groupPosition.getItemList().size();
System.out.println(“组[“+groupPosition+”]的子级为[“+size+”]);
返回大小;
}
@凌驾
公共对象getGroup(int-groupPosition){
返回catList.get(groupPosition);
}
@凌驾
public int getGroupCount(){
返回catList.size();
}
@凌驾
公共长getGroupId(int-groupPosition){
返回catList.get(groupPosition.hashCode();
}
@凌驾
公共视图getGroupView(int-groupPosition,布尔值isExpanded,
视图(视图、视图组父级){
视图v=转换视图;
如果(v==null){
LayoutInflater充气器=(LayoutInflater)ctx.getSystemService
(上下文、布局、充气机和服务);
v=充气机。充气(R.layout.group_布局,父级,false);
}
TextView组名=(TextView)v.findViewById(R.id.groupName);
GroupCat=catList.get(groupPosition);
groupName.setText(cat.getGroupName());
返回v;
}
@凌驾
公共布尔表ID(){
返回true;
}
@凌驾
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
返回true;
}
}

公共类NewGraveActivity扩展活动{
ExpandableListView类别列表;
私人名单;
选择公共哈希图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
initData();
setContentView(R.layout.activity_newgrave);
/////////////////////////////---类别列表视图--///////////////////
selected=newhashmap();
ExpandableListView exList=(ExpandableListView)findViewById(R.id.expandableListView1);
exList.setIndicatorBounds(5,5);
ExpandableAdapter exAdpt=新的ExpandableAdapter(catList,this,this);
exList.setIndicatorBounds(0,20);
exList.setAdapter(exAdpt);
}
私有void initData(){
catList=newarraylist();
GroupCat cat1=创建类别(“类别”,1);
cat1.setItemList(createItems());
catList.add(cat1);
Log.d(“NewGrave initData”,“Liste von Kategroien Erstellet”);
}
private GroupCat CreateContegory(字符串名称,长id){
Log.d(“NewGrave CreateContegory”、“Kategorie erzeugen”);
返回新的GroupCat(id,name);
}
私有列表createItems(){
列表结果=新建ArrayList();
String[]数组=getResources().getStringArray(R.array.categoryNames);
for(int i=0;i
}

以下是我的xml布局文件:

活动总体布局:

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/labelInCategories"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/labelInCategories" />

        <ExpandableListView
            android:id="@+id/expandableListView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" >
       </ExpandableListView>

        <Button
            android:id="@+id/buttonNewGrave"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/buttonNewGrave" />


    </LinearLayout>

</ScrollView>

ExpandableListView中的组布局

<?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/groupName"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="15dip" />

    <TextView
        android:id="@+id/groupDescr"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="8dip" />

</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" >

    <CheckBox
        android:id="@+id/itemCheck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />

    <TextView
        android:id="@+id/itemName"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />
</LinearLayout>

ExpandableListView中项目的布局

<?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/groupName"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="15dip" />

    <TextView
        android:id="@+id/groupDescr"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="8dip" />

</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" >

    <CheckBox
        android:id="@+id/itemCheck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />

    <TextView
        android:id="@+id/itemName"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />
</LinearLayout>


单击组项目时会发生什么情况?它没有展开,或者显示了错误的子项?而
xml
groupitem
布局就只有这么多??在您最新的代码中,您没有向
xml
添加任何其他元素,比如
button
,对吗?是的,整个项目的原始xml有更多视图,包括按钮。可扩展的第一眼看上去很好-团队就在那里。我可以点击它,小箭头会改变,但项目不会显示。我确信这些项目是存在的——我记录了列表,它确实有内容。你能发布原始的xml吗?它有按钮吗?实际上,在第一个(“主”)xml中只有这一个按钮。它保存了所有用户输入。是否需要另一个按钮来保存exp.listview的状态?