Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.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
Java Android ExpandableListView不是';在应用程序中不可见_Java_Android_Xml_Exp - Fatal编程技术网

Java Android ExpandableListView不是';在应用程序中不可见

Java Android ExpandableListView不是';在应用程序中不可见,java,android,xml,exp,Java,Android,Xml,Exp,我正试图在Android中制作一个ExpandableListView,其中显示了一系列问题。当我运行应用程序时,屏幕上不会显示任何内容。我不知道这是为什么或者如何发生的。有人能帮我吗 我不想说明我从服务器获取数据,这些数据保存在对象中(也称为问题)。我已经测试了很多次,这段代码没有任何问题。因此,要显示的数据可用,但不会显示在应用程序中 我正在使用以下代码: 占位符片段: public static class PlaceholderFragment extends Fragment {

我正试图在Android中制作一个
ExpandableListView
,其中显示了一系列问题。当我运行应用程序时,屏幕上不会显示任何内容。我不知道这是为什么或者如何发生的。有人能帮我吗

我不想说明我从服务器获取数据,这些数据保存在对象中(也称为问题)。我已经测试了很多次,这段代码没有任何问题。因此,要显示的数据可用,但不会显示在应用程序中

我正在使用以下代码:

占位符片段:

public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        // Progress dialog
        private ProgressDialog pDialog;

        private static String TAG = Problems.class.getSimpleName();

        private ArrayList<Problem> myProblems = new ArrayList<Problem>();

        private SparseArray<Group> groups = new SparseArray<Group>();

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {

            //Here comes code that handles data input from server ( which correctly works btw )

            for(int i = 0; i < myProblems.size(); i++){
                Group group = new Group(myProblems.get(i).getTitle());
                group.children.add(myProblems.get(i).domainsToString());
                group.children.add(myProblems.get(i).getDescription());
                groups.append(i, group);
            }

            View rootView = inflater.inflate(R.layout.fragment_my_problems, container, false);

            mMyProblems = (ExpandableListView) rootView.findViewById(R.id.my_problems);
            //mMyProblems.setAdapter(adapterMyP);
            MyProblemExpandableListViewAdapter adapter = new MyProblemExpandableListViewAdapter(this.getActivity(), groups);
            mMyProblems.setAdapter(adapter);

            return rootView;
        }

        private void showpDialog() {
            if (!pDialog.isShowing())
                pDialog.show();
        }

        private void hidepDialog() {
            if (pDialog.isShowing())
                pDialog.dismiss();
        }

    }
public class MyProblemExpandableListViewAdapter extends BaseExpandableListAdapter {
    private final SparseArray<Group> groups;
    public LayoutInflater inflater;
    public Activity activity;

    public MyProblemExpandableListViewAdapter(Activity act, SparseArray<Group> groups) {
        activity = act;
        this.groups = groups;
        inflater = act.getLayoutInflater();
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return groups.get(groupPosition).children.get(childPosition);
    }

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

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        final String children = (String) getChild(groupPosition, childPosition);
        TextView text = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listrow_details, null);
        }
        text = (TextView) convertView.findViewById(R.id.textView1);
        text.setText(children);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(activity, children,
                        Toast.LENGTH_SHORT).show();
            }
        });
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return groups.get(groupPosition).children.size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return groups.size();
    }

    @Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listrow_group, null);
        }
        Group group = (Group) getGroup(groupPosition);
        ((CheckedTextView) convertView).setText(group.string);
        ((CheckedTextView) convertView).setChecked(isExpanded);
        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

}
public class Group {
    public String string;
    public final List<String> children = new ArrayList<String>();

    public Group(String string) {
        this.string = string;
    }
}
公共静态类占位符片段扩展片段{
/**
*表示此文件节号的片段参数
*碎片。
*/
私有静态最终字符串ARG\u SECTION\u NUMBER=“SECTION\u NUMBER”;
//进度对话框
私人对话;
私有静态字符串标记=Problems.class.getSimpleName();
private ArrayList myProblems=new ArrayList();
私有SparseArray组=新SparseArray();
/**
*返回给定节的此片段的新实例
*号码。
*/
公共静态占位符片段newInstance(int sectionNumber){
占位符片段=新占位符片段();
Bundle args=新Bundle();
参数Putin(参数段号,段号);
fragment.setArguments(args);
返回片段;
}
公共占位符片段(){
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//下面是处理来自服务器的数据输入的代码(顺便说一句,它可以正常工作)
对于(int i=0;i
适配器:

public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        // Progress dialog
        private ProgressDialog pDialog;

        private static String TAG = Problems.class.getSimpleName();

        private ArrayList<Problem> myProblems = new ArrayList<Problem>();

        private SparseArray<Group> groups = new SparseArray<Group>();

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {

            //Here comes code that handles data input from server ( which correctly works btw )

            for(int i = 0; i < myProblems.size(); i++){
                Group group = new Group(myProblems.get(i).getTitle());
                group.children.add(myProblems.get(i).domainsToString());
                group.children.add(myProblems.get(i).getDescription());
                groups.append(i, group);
            }

            View rootView = inflater.inflate(R.layout.fragment_my_problems, container, false);

            mMyProblems = (ExpandableListView) rootView.findViewById(R.id.my_problems);
            //mMyProblems.setAdapter(adapterMyP);
            MyProblemExpandableListViewAdapter adapter = new MyProblemExpandableListViewAdapter(this.getActivity(), groups);
            mMyProblems.setAdapter(adapter);

            return rootView;
        }

        private void showpDialog() {
            if (!pDialog.isShowing())
                pDialog.show();
        }

        private void hidepDialog() {
            if (pDialog.isShowing())
                pDialog.dismiss();
        }

    }
public class MyProblemExpandableListViewAdapter extends BaseExpandableListAdapter {
    private final SparseArray<Group> groups;
    public LayoutInflater inflater;
    public Activity activity;

    public MyProblemExpandableListViewAdapter(Activity act, SparseArray<Group> groups) {
        activity = act;
        this.groups = groups;
        inflater = act.getLayoutInflater();
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return groups.get(groupPosition).children.get(childPosition);
    }

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

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        final String children = (String) getChild(groupPosition, childPosition);
        TextView text = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listrow_details, null);
        }
        text = (TextView) convertView.findViewById(R.id.textView1);
        text.setText(children);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(activity, children,
                        Toast.LENGTH_SHORT).show();
            }
        });
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return groups.get(groupPosition).children.size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return groups.size();
    }

    @Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listrow_group, null);
        }
        Group group = (Group) getGroup(groupPosition);
        ((CheckedTextView) convertView).setText(group.string);
        ((CheckedTextView) convertView).setChecked(isExpanded);
        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

}
public class Group {
    public String string;
    public final List<String> children = new ArrayList<String>();

    public Group(String string) {
        this.string = string;
    }
}
公共类MyProblemExpandableListViewAdapter扩展了BaseExpandableListAdapter{
私人最终Sparsarray集团;
公共场所;充气机;
公共活动;
公共MyProblemExpandableListViewAdapter(活动法案,SparseArray组){
活动=行动;
这个组=组;
充气器=act.getLayoutFlater();
}
@凌驾
公共对象getChild(int-groupPosition,int-childPosition){
返回groups.get(groupPosition).children.get(childPosition);
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回0;
}
@凌驾
公共视图getChildView(int groupPosition,final int childPosition,
布尔值isLastChild、视图转换视图、视图组父级){
最终字符串children=(String)getChild(groupPosition,childPosition);
TextView text=null;
if(convertView==null){
convertView=充气机。充气(R.layout.listrow\u详细信息,空);
}
text=(TextView)convertView.findViewById(R.id.textView1);
text.setText(儿童);
convertView.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(活动、儿童、,
吐司。长度(短)。show();
}
});
返回视图;
}
@凌驾
公共整数getChildrenCount(整数组位置){
返回groups.get(groupPosition.children.size();
}
@凌驾
公共对象getGroup(int-groupPosition){
返回groups.get(groupPosition);
}
@凌驾
public int getGroupCount(){
返回组。size();
}
@凌驾
公共void-ongroupposition(int-groupPosition){
super.ongroupposition(groupPosition);
}
@凌驾
已扩展的公共组(int-groupPosition){
super.onGroupExpanded(groupPosition);
}
@凌驾
公共长getGroupId(int-groupPosition){
返回0;
}
@凌驾
公共视图getGroupView(int-groupPosition,布尔值isExpanded,
视图(视图、视图组父级){
if(convertView==null){
convertView=充气机。充气(R.layout.listrow_组,空);
}
组组=(组)getGroup(组位置);
((CheckedTextView)convertView).setText(group.string);
((CheckedTextView)convertView).setChecked(isExpanded);
返回视图;
}
@凌驾
公共布尔表ID(){
返回false;
}
@凌驾
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
返回false;
}
}
和组类:

public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        // Progress dialog
        private ProgressDialog pDialog;

        private static String TAG = Problems.class.getSimpleName();

        private ArrayList<Problem> myProblems = new ArrayList<Problem>();

        private SparseArray<Group> groups = new SparseArray<Group>();

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {

            //Here comes code that handles data input from server ( which correctly works btw )

            for(int i = 0; i < myProblems.size(); i++){
                Group group = new Group(myProblems.get(i).getTitle());
                group.children.add(myProblems.get(i).domainsToString());
                group.children.add(myProblems.get(i).getDescription());
                groups.append(i, group);
            }

            View rootView = inflater.inflate(R.layout.fragment_my_problems, container, false);

            mMyProblems = (ExpandableListView) rootView.findViewById(R.id.my_problems);
            //mMyProblems.setAdapter(adapterMyP);
            MyProblemExpandableListViewAdapter adapter = new MyProblemExpandableListViewAdapter(this.getActivity(), groups);
            mMyProblems.setAdapter(adapter);

            return rootView;
        }

        private void showpDialog() {
            if (!pDialog.isShowing())
                pDialog.show();
        }

        private void hidepDialog() {
            if (pDialog.isShowing())
                pDialog.dismiss();
        }

    }
public class MyProblemExpandableListViewAdapter extends BaseExpandableListAdapter {
    private final SparseArray<Group> groups;
    public LayoutInflater inflater;
    public Activity activity;

    public MyProblemExpandableListViewAdapter(Activity act, SparseArray<Group> groups) {
        activity = act;
        this.groups = groups;
        inflater = act.getLayoutInflater();
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return groups.get(groupPosition).children.get(childPosition);
    }

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

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {
        final String children = (String) getChild(groupPosition, childPosition);
        TextView text = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listrow_details, null);
        }
        text = (TextView) convertView.findViewById(R.id.textView1);
        text.setText(children);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(activity, children,
                        Toast.LENGTH_SHORT).show();
            }
        });
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return groups.get(groupPosition).children.size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return groups.size();
    }

    @Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listrow_group, null);
        }
        Group group = (Group) getGroup(groupPosition);
        ((CheckedTextView) convertView).setText(group.string);
        ((CheckedTextView) convertView).setChecked(isExpanded);
        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

}
public class Group {
    public String string;
    public final List<String> children = new ArrayList<String>();

    public Group(String string) {
        this.string = string;
    }
}
公共类组{
公共字符串;
public final List children=new ArrayList();
公共组(字符串){
this.string=string;
}
}
以及相应的xml文件:

fragementMyProblems.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.wsi.wesupportit.Problems$PlaceholderFragment" >

    <ExpandableListView
        android:id="@+id/my_problems"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ExpandableListView>

</LinearLayout>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:layout_marginLeft="8dp"
    android:gravity="left"
    android:paddingLeft="32dp"
    android:paddingTop="8dp"
    android:text="Test"
    android:textSize="14sp"
    android:textStyle="bold" />
<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="40dp"
    android:clickable="true"android:orientation="vertical"
    android:paddingLeft="40dp">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawablePadding="5dp"
        android:gravity="center_vertical"
        android:text="@string/hello_world"
        android:textSize="14sp"
        android:textStyle="bold" >
    </TextView>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/black" />

</LinearLayout>