0

就好像他们根本不存在一样。它可以编译,但在每个组中都没有可见或可选择的内容。这是一个屏幕截图:

在此处输入图像描述

这是我的活动课。孩子们的膨胀 xml 几乎没有。

package com.anthonyce.mcathomie;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PlayoptionsActivity extends Activity {
ExpandableListView Mtopics;
ExpandableAdapter MtopicsAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_playoptions);
    //set up adapter
    MtopicsAdapter = new ExpandableAdapter();
    Mtopics = (ExpandableListView) findViewById(R.id.mtopicsListView);
    Mtopics.setAdapter(MtopicsAdapter);
    //Mtopics.setGroupIndicator(null);
}

public class ExpandableAdapter extends BaseExpandableListAdapter {
        private String[] groups = { "People Names", "Dog Names", "Cat Names",
        "Fish Names" };
private String[][] children = { { "Arnold" }, { "Ace" }, { "Fluffy" },
        { "Goldy" } };

    public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition][childPosition];
    }

    public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
    }

    public View getChildView(final int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        final class ExpandChildRow extends LinearLayout {
            public ExpandChildRow(Context context) {
                super(context);
                LayoutInflater childInflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                LinearLayout childView = (LinearLayout) childInflate.inflate(R.layout.mtopics_childrow, this, true);

                TextView childtxt = (TextView)childView.findViewById(R.id.mtopicchildtext);
                childtxt.setText(getChild(groupPosition, childPosition).toString());
            }
        }

        ExpandChildRow ChildRow = new ExpandChildRow(getBaseContext());
        return ChildRow;
    }

    public int getChildrenCount(int groupPosition) {
        return children[groupPosition].length;
    }

    public Object getGroup(int groupPosition) {
        return groups[groupPosition];
    }

    public int getGroupCount() {
        return groups.length;
    }

    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    public View getGroupView(final int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {

        final class ExpandGroupRow extends LinearLayout {
            public ExpandGroupRow(Context context) {
                super(context);
                LayoutInflater groupInflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                LinearLayout groupView = (LinearLayout) groupInflate.inflate(R.layout.mtopics_grouprow, this, true);

                TextView grouptxt = (TextView)groupView.findViewById(R.id.mtopicgrouptext);
                grouptxt.setText(getGroup(groupPosition).toString());
            }
        }

        ExpandGroupRow GroupRow = new ExpandGroupRow(getBaseContext());
        return GroupRow;

    }

    public boolean hasStableIds() {
        return true;
    }

    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

}
}
4

2 回答 2

1

哦,我太菜鸟了。它起作用的原因是因为组行上任何位置的复选框与组分隔符或类似的东西冲突。也许组分隔符实际上是一个复选框。我只是删除了复选框,一切都恢复了。我想我的布局 xml 文件需要修改。

于 2012-09-06T05:57:42.473 回答
1

我认为问题在于:class ExpandGroupRow extends LinearLayout 您正在尝试将此类用作 UI 元素,但您没有this在构造函数中设置布局参数。仅使用充气器返回的 LinearLayout 而不是此类可能更容易。就像是:

public View getGroupView(final int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {

            LayoutInflater groupInflate = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            LinearLayout groupView = (LinearLayout) groupInflate.inflate(R.layout.mtopics_grouprow, parent, false);

            TextView grouptxt = (TextView)groupView.findViewById(R.id.mtopicgrouptext);
            grouptxt.setText(getGroup(groupPosition).toString());
            return groupView;

}
于 2012-09-06T00:52:53.427 回答