Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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 具有不同组视图的可扩展ListView_Android_Expandablelistview_Expandablelistadapter - Fatal编程技术网

Android 具有不同组视图的可扩展ListView

Android 具有不同组视图的可扩展ListView,android,expandablelistview,expandablelistadapter,Android,Expandablelistview,Expandablelistadapter,我正在使用一个问题数据库,我需要为它实现一个可扩展的Listview ++TextView (Question)++ ->Option 1 ->Option 2 ->Option 3 ->Option 4 ++EditText (Input Question)++ It has no options at all ++TextView (Question)++ ->Option 1 ->Option 2 ->Optio

我正在使用一个问题数据库,我需要为它实现一个可扩展的Listview

++TextView (Question)++
  ->Option 1
  ->Option 2
  ->Option 3
  ->Option 4

++EditText (Input Question)++
  It has no options at all

++TextView (Question)++
  ->Option 1
  ->Option 2
  ->Option 3
  ->Option 4
我的可扩展适配器中存在不同组类型的问题。
我已经看过了,但是没有这种类型的结构的链接或教程。

我看过这个教程,但是它也实现了普通的可扩展列表视图示例,其中每个组项都是相同的。我需要的是不同的组项。
please follow these code.
    public class RevisionPaperChemistryList extends ExpandableListActivity {
        // Create ArrayList to hold parent Items and Child Items
        private ArrayList<String> parentItems = new ArrayList<String>();
        private ArrayList<Object> childItems = new ArrayList<Object>();
        private ArrayList<Integer> childimage = new ArrayList<Integer>();
        private ArrayList<Integer> parentimage = new ArrayList<Integer>();
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            // Create Expandable List and set it's properties
            ExpandableListView expandableList = getExpandableListView();
            expandableList.setDividerHeight(2);
            expandableList.setGroupIndicator(null);
            expandableList.setClickable(true);
            expandableList.setBackgroundResource(R.drawable.all_background);
            // Set the Items of Parent
            setGroupParents();
            // Set The Child Data
            setChildData();
            // Create the Adapter
            MyExpandableAdapter adapter = new MyExpandableAdapter(parentItems, childItems);
            adapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), this);
           // Set the Adapter to expandableList
            expandableList.setAdapter(adapter);
            expandableList.setOnChildClickListener(this);
        }
        // method to add parent Items
        public void setGroupParents()
        {

            parentItems.add("CHEMISTRY");
            parentItems.add("MATHMATICS");
            parentItems.add("PHYSICS");
            parentimage.add(R.drawable.chemistry);
            parentimage.add(R.drawable.mathematics);
            parentimage.add(R.drawable.physics);

        }
     // method to set child data of each parent
        public void setChildData() {
            // Add Child Items for Fruits
            ArrayList<String> child = new ArrayList<String>();
                child.add("Some Basic Concepts");
                child.add("States of Matter");
                child.add("Atomic Structure");

                childItems.add(child);

                child = new ArrayList<String>();

                child = new ArrayList<String>();

                child.add("Paper_1");
                child.add("Paper_2");
                child.add("Paper_3");
                child.add("Paper_4");
                child.add("Paper_5");
                childItems.add(child);

            }

       public class MyExpandableAdapter extends BaseExpandableListAdapter
        {
            private Activity activity;
            private ArrayList<Object> childtems;
            private LayoutInflater inflater;
            private ArrayList<String> parentItems, child;
       public MyExpandableAdapter(ArrayList<String> parents, ArrayList<Object> childern)
            {
                this.parentItems = parents;
                this.childtems = childern;
            }
            public void setInflater(LayoutInflater inflater, Activity activity)
            {
                this.inflater = inflater;
                this.activity = activity;
            }
            @SuppressWarnings("unchecked")
            @Override

     public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
            {
                child = (ArrayList<String>) childtems.get(groupPosition);
                TextView textView = null;
                if (convertView == null)
                {
                    convertView = inflater.inflate(R.layout.child_view, null);
                }
                textView = (TextView) convertView.findViewById(R.id.textViewChild);
                textView.setText(child.get(childPosition));
                convertView.setOnClickListener(new OnClickListener() {
                @Override
                 public void onClick(View view)
                {

                }
                });
                return convertView;
                }
               @SuppressLint("NewApi")
            @Override

      public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
                {
                if (convertView == null)
                {
                    convertView = inflater.inflate(R.layout.chemistry_parent_view, null);

                }

                ((CheckedTextView) convertView).setText(parentItems.get(groupPosition));
                ((CheckedTextView) convertView).setCompoundDrawablesWithIntrinsicBounds(parentimage.get(groupPosition), 0, R.drawable.downward, 0);
                ((CheckedTextView) convertView).setChecked(isExpanded);
                return convertView;
            }
            @Override
            public Object getChild(int groupPosition, int childPosition)
            {
                return null;
            }
            @Override
            public long getChildId(int groupPosition, int childPosition)
            {
                return 0;
            }
            @SuppressWarnings("unchecked")
            @Override
           public int getChildrenCount(int groupPosition)
            {
                return ((ArrayList<String>) childtems.get(groupPosition)).size();
            }
            @Override
            public Object getGroup(int groupPosition)
            {
                return null;
            }
            @Override
            public int getGroupCount()
            {
                return parentItems.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 boolean hasStableIds()
            {
                return false;
            }
            @Override
            public boolean isChildSelectable(int groupPosition, int childPosition)
            {
                return false;
            }

        }

    }