Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ExpandableListView不工作(黑色/空屏幕)_Android_Screen_Adapter_Expandablelistview - Fatal编程技术网

Android ExpandableListView不工作(黑色/空屏幕)

Android ExpandableListView不工作(黑色/空屏幕),android,screen,adapter,expandablelistview,Android,Screen,Adapter,Expandablelistview,我尝试使用自己的ExpandableListAdapter构建ExpandableListView,但ExpandableListView在我的活动中不可见:-( 下面是我的源代码 谢谢你的帮助:-) 您好, 康吉 下面是活动的代码: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.group_main

我尝试使用自己的ExpandableListAdapter构建ExpandableListView,但ExpandableListView在我的活动中不可见:-(

下面是我的源代码

谢谢你的帮助:-)

您好, 康吉

下面是活动的代码:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.group_main);

    onCreateDBAndDBTabled();

    mAddGroupButton = (Button) findViewById(R.id.Button_Add_Group);
    mAddGroupButton.setOnClickListener(this);

    mExpandableList = (ExpandableListView) findViewById(R.id.ExpandableListView01);

    ArrayList<ExpandableListItem> valueTree = new ArrayList<ExpandableListItem>();

    ExpandableListItem gp1 = new ExpandableListItem();
    gp1.putProperty("name", "e");

    ExpandableListItem gp11 = new ExpandableListItem();
    gp11.putProperty("name", "l");

    gp1.addChild(gp11);

    ExpandableListItem gp2 = new ExpandableListItem();
    gp2.putProperty("name", "A");

    ExpandableListItem gp22 = new ExpandableListItem();
    gp22.putProperty("name", "B");  
    ExpandableListItem gp23 = new ExpandableListItem();
    gp23.putProperty("name", "A1");
    ExpandableListItem gp24 = new ExpandableListItem();
    gp24.putProperty("name", "A3");
    ExpandableListItem gp25 = new ExpandableListItem();
    gp25.putProperty("name", "A4");

    gp2.addChild(gp22);
    gp2.addChild(gp23);
    gp2.addChild(gp24);
    gp2.addChild(gp25);

    valueTree.add(gp1);
    valueTree.add(gp2);

    Log.d("onCreate", "hasChild " + gp1.hasChilds());
    Log.d("onCreate", "hasChild " + gp2.hasChilds());


    MyColoredExpandableListAdapter adapter = new MyColoredExpandableListAdapter(this, valueTree);

    mExpandableList.setAdapter(adapter);



}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.group_main);
onCreateDBAndDBTabled();
mAddGroupButton=(Button)findViewById(R.id.Button\u Add\u Group);
mAddGroupButton.setOnClickListener(此);
mExpandableList=(ExpandableListView)findViewById(R.id.ExpandableListView01);
ArrayList valueTree=新的ArrayList();
ExpandableListItem gp1=新的ExpandableListItem();
gp1.不动产(“名称”、“e”);
ExpandableListItem gp11=新的ExpandableListItem();
gp11.不动产(“名称”、“l”);
gp1.addChild(gp11);
ExpandableListItem gp2=新的ExpandableListItem();
gp2.不动产(“名称”、“A”);
ExpandableListItem gp22=新的ExpandableListItem();
gp22.不动产(“名称”、“B”);
ExpandableListItem gp23=新的ExpandableListItem();
gp23.不动产(“名称”、“A1”);
ExpandableListItem gp24=新的ExpandableListItem();
gp24.不动产(“名称”、“A3”);
ExpandableListItem gp25=新的ExpandableListItem();
gp25.不动产(“名称”、“A4”);
gp2.addChild(gp22);
gp2.addChild(gp23);
gp2.addChild(gp24);
gp2.addChild(gp25);
valueTree.add(gp1);
valueTree.add(gp2);
Log.d(“onCreate”,“hasChild”+gp1.hasChilds());
Log.d(“onCreate”,“hasChild”+gp2.hasChilds());
MyColoredExpandableListAdapter=新的MyColoredExpandableListAdapter(此,valueTree);
setAdapter(适配器);
}
代码MyColoredExpandableListAdapter:

private class MyColoredExpandableListAdapter extends MyExpandableListAdapter{



    public MyColoredExpandableListAdapter(Context context,

            ArrayList<ExpandableListItem> valueTree) {
        super(context, valueTree);

        Log.d("MyColoredExpandableListAdapter", "Group Count" + this.getGroupCount());

        for(int i = 0; i < this.getGroupCount(); i++)
            Log.d("MyColoredExpandableListAdapter", "Child Count" + this.getChildrenCount(i));

        // TODO Auto-generated constructor stub
    }

    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        Log.d("getChildView", "GO INTO");

        if(convertView == null){
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.group_exp_childs, null);
        }
            TextView text = (TextView) convertView.findViewById(R.id.TextView_Group_EXP_Childs);

            text.setText(">>" + this.mValueTree.get(groupPosition).getChild(childPosition).getProperty("name"));


        return convertView;
    }

    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

            Log.d("getGroupView", "GO INTO");

            if(convertView == null){
                LayoutInflater inflater = LayoutInflater.from(mContext);
                convertView = inflater.inflate(R.layout.group_exp_childs, null);
            }

            TextView text = (TextView) convertView.findViewById(R.id.TextView_Group_EXP_Childs);

            text.setText(">" + this.mValueTree.get(groupPosition).getProperty("name"));


        return convertView;
    }

}
public abstract class MyExpandableListAdapter extends BaseExpandableListAdapter {

protected Context mContext;
protected ArrayList<ExpandableListItem> mValueTree;

public MyExpandableListAdapter(Context context, 

        ArrayList<ExpandableListItem> valueTree)
{
    mContext = context;
    mValueTree = valueTree;

}

public Object getChild(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub

    if(mValueTree.get(groupPosition).hasChilds())
        return mValueTree.get(groupPosition).getChild(childPosition);

    return null;
}

public long getChildId(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return childPosition; // WE NEED NO SPECIAL ID 
}



public int getChildrenCount(int groupPosition) {
    // TODO Auto-generated method stub

    if(mValueTree.get(groupPosition).hasChilds())
        return mValueTree.get(groupPosition).sizeOfChilds();

    return 0;
}

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

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

public long getGroupId(int groupPosition) {
    // TODO Auto-generated method stub
    return groupPosition; // WE NEED NO SPECIAL ID 
}

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

public boolean isChildSelectable(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return true;
}
私有类MyColoredExpandableListAdapter扩展MyExpandableListAdapter{
公共MyColoredExpandableListAdapter(上下文,
ArrayList valueTree){
super(上下文,valueTree);
Log.d(“MyColoredExpandableListAdapter”、“组计数”+this.getGroupCount());
对于(int i=0;i>”+this.mValueTree.get(groupPosition).getChild(childPosition.getProperty(“name”);
返回视图;
}
公共视图getGroupView(int-groupPosition,布尔值isExpanded,
视图(视图、视图组父级){
//TODO自动生成的方法存根
Log.d(“getGroupView”、“进入”);
if(convertView==null){
LayoutFlater充气机=LayoutFlater.from(mContext);
convertView=充气机。充气(R.layout.group\u exp\u childs,null);
}
TextView text=(TextView)convertView.findViewById(R.id.TextView\u Group\u EXP\u Childs);
text.setText(“>”+this.mValueTree.get(groupPosition.getProperty(“name”));
返回视图;
}
}
代码MyExpandableListAdapter:

private class MyColoredExpandableListAdapter extends MyExpandableListAdapter{



    public MyColoredExpandableListAdapter(Context context,

            ArrayList<ExpandableListItem> valueTree) {
        super(context, valueTree);

        Log.d("MyColoredExpandableListAdapter", "Group Count" + this.getGroupCount());

        for(int i = 0; i < this.getGroupCount(); i++)
            Log.d("MyColoredExpandableListAdapter", "Child Count" + this.getChildrenCount(i));

        // TODO Auto-generated constructor stub
    }

    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        Log.d("getChildView", "GO INTO");

        if(convertView == null){
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.group_exp_childs, null);
        }
            TextView text = (TextView) convertView.findViewById(R.id.TextView_Group_EXP_Childs);

            text.setText(">>" + this.mValueTree.get(groupPosition).getChild(childPosition).getProperty("name"));


        return convertView;
    }

    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

            Log.d("getGroupView", "GO INTO");

            if(convertView == null){
                LayoutInflater inflater = LayoutInflater.from(mContext);
                convertView = inflater.inflate(R.layout.group_exp_childs, null);
            }

            TextView text = (TextView) convertView.findViewById(R.id.TextView_Group_EXP_Childs);

            text.setText(">" + this.mValueTree.get(groupPosition).getProperty("name"));


        return convertView;
    }

}
public abstract class MyExpandableListAdapter extends BaseExpandableListAdapter {

protected Context mContext;
protected ArrayList<ExpandableListItem> mValueTree;

public MyExpandableListAdapter(Context context, 

        ArrayList<ExpandableListItem> valueTree)
{
    mContext = context;
    mValueTree = valueTree;

}

public Object getChild(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub

    if(mValueTree.get(groupPosition).hasChilds())
        return mValueTree.get(groupPosition).getChild(childPosition);

    return null;
}

public long getChildId(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return childPosition; // WE NEED NO SPECIAL ID 
}



public int getChildrenCount(int groupPosition) {
    // TODO Auto-generated method stub

    if(mValueTree.get(groupPosition).hasChilds())
        return mValueTree.get(groupPosition).sizeOfChilds();

    return 0;
}

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

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

public long getGroupId(int groupPosition) {
    // TODO Auto-generated method stub
    return groupPosition; // WE NEED NO SPECIAL ID 
}

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

public boolean isChildSelectable(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return true;
}
公共抽象类MyExpandableListAdapter扩展了BaseExpandableListAdapter{
保护上下文mContext;
受保护的数组列表树;
公共MyExpandableListAdapter(上下文,
ArrayList valueTree)
{
mContext=上下文;
mValueTree=valueTree;
}
公共对象getChild(int-groupPosition,int-childPosition){
//TODO自动生成的方法存根
if(mValueTree.get(groupPosition.hasChilds())
返回mValueTree.get(groupPosition).getChild(childPosition);
返回null;
}
公共长getChildId(int-groupPosition,int-childPosition){
//TODO自动生成的方法存根
return childPosition;//我们不需要特殊的ID
}
公共整数getChildrenCount(整数组位置){
//TODO自动生成的方法存根
if(mValueTree.get(groupPosition.hasChilds())
返回mValueTree.get(groupPosition.sizeOfChilds();
返回0;
}
公共对象getGroup(int-groupPosition){
//TODO自动生成的方法存根
返回mValueTree.get(groupPosition);
}
public int getGroupCount(){
//TODO自动生成的方法存根
返回mValueTree.size();
}
公共长getGroupId(int-groupPosition){
//TODO自动生成的方法存根
return groupPosition;//我们不需要特殊的ID
}
公共布尔表ID(){
//TODO自动生成的方法存根
返回false;
}
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
//TODO自动生成的方法存根
返回true;
}
}

代码ExpandableListItem:

public class ExpandableListItem {

private HashMap<String,String> properties = new HashMap<String,String>();

public void clearProperties() {
    properties.clear();
}
public boolean containsPropertyKey(String key) {
    return properties.containsKey(key);
}
public boolean containsPropertyValue(String value) {
    return properties.containsValue(value);
}
public String getProperty(String key) {
    return properties.get(key);
}
public boolean hasProperties() {
    return !properties.isEmpty();
}
public String putProperty(String key, String value) {
    return properties.put(key, value);
}
public String removeProperty(String key) {
    return properties.remove(key);
}
public int sizeOfProperties() {
    return properties.size();
}

public String[] propertiesKeys()
{
    int count = 0;
    String[] result = new String[sizeOfProperties()];

    for(String key : this.properties.keySet())
        result[count++] = key;

    return result;
}

private ArrayList<ExpandableListItem> childs = new ArrayList<ExpandableListItem>();

public boolean addChild(ExpandableListItem object) {
    return childs.add(object);
}
public void clearChilds() {
    childs.clear();
}
public ExpandableListItem getChild(int index) {
    return childs.get(index);
}
public boolean hasChilds() {
    return !childs.isEmpty();
}
public ExpandableListItem removeChild(int index) {
    return childs.remove(index);
}
public int sizeOfChilds() {
    return childs.size();
}
公共类ExpandableListItem{
私有HashMap属性=新HashMap();
公共无效clearProperties(){
properties.clear();
}
公共布尔值containsPropertyKey(字符串键){
返回属性.containsKey(键);
}
公共布尔值containsPropertyValue(字符串值){
返回属性。containsValue(value);
}
公共字符串getProperty(字符串键){
返回properties.get(key);
}
公共布尔属性(){
return!properties.isEmpty();
}
公共字符串属性(字符串键、字符串值){
返回properties.put(key,value);
}
公共字符串移除属性(字符串键){
返回属性。删除(键);
}
public int sizeofproperty(){
返回properties.size();
}
公共字符串[]propertiesKeys()
{
整数计数=0;
字符串[]