0

我正在努力讓Expandable List View旁邊有圖像和文字。我曾經最本例中的工作,而我在這裏找到ExpandableListView

--->How to add image in expandable List in parent in android?

但我不斷收到Error

01-07 22:42:26.182: E/AndroidRuntime(28475): at gui.ExpandActivity$1.getChildView(ExpandActivity.java:115) 
01-07 22:42:26.182: E/AndroidRuntime(28475): at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:450) 

有什麼想法?謝謝。

// Construct Expandable List 
      final String NAME = "name"; 
      final String IMAGE = "image"; 
      final LayoutInflater layoutInflater = (LayoutInflater) this 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>(); 

      final HashMap<String, String> group1 = new HashMap<String, String>(); 
      group1.put(NAME, "Group 1"); 
      headerData.add(group1); 

      final HashMap<String, String> group2 = new HashMap<String, String>(); 
      group2.put(NAME, "Group 2"); 
      headerData.add(group2); 

      final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>(); 

      final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>(); 
      childData.add(group1data); 

      final ArrayList<HashMap<String, Object>> group2data = new ArrayList<HashMap<String, Object>>(); 
      childData.add(group2data); 

      // Set up some sample data in both groups 
      for (int i = 0; i < 10; ++i) { 
       final HashMap<String, Object> map = new HashMap<String, Object>(); 
       map.put(NAME, "Child " + i); 
       map.put(IMAGE, 
         getResources().getDrawable(R.drawable.ic_launcher)); 
       (i % 2 == 0 ? group1data : group2data).add(map); 
      } 

      setListAdapter(new SimpleExpandableListAdapter(this, 
        headerData, android.R.layout.simple_expandable_list_item_1, 
        new String[] { NAME }, // the name of the field data 
        new int[] { android.R.id.text1 }, // the text field to 
                 // populate with the 
                 // field data 
        childData, 0, null, new int[] {}) { 
       @Override 
       public View getChildView(int groupPosition, int childPosition, 
         boolean isLastChild, View convertView, ViewGroup parent) { 
        final View v = super.getChildView(groupPosition, 
          childPosition, isLastChild, convertView, parent); 

        // Populate your custom view here 
        // ((TextView) v.findViewById(R.id.name)) 
        // .setText((String) ((HashMap<String, Object>) getChild(
        // groupPosition, childPosition)).get(NAME)); 
        // ((ImageView) v.findViewById(R.id.image)) 
        // .setImageDrawable((Drawable) ((HashMap<String, Object>) 
        // getChild(
        // groupPosition, childPosition)).get(IMAGE)); 

        ((TextView) v.findViewById(R.id.name)) 
          .setText("This should be child one corrent?"); 
        // ((ImageView) v.findViewById(R.id.image)) 
        // .setImageDrawable((Drawable) getResources() 
        // .getDrawable(R.drawable.ic_launcher)); 

        return v; 
       } 

       @Override 
       public View newChildView(boolean isLastChild, ViewGroup parent) { 
        return layoutInflater.inflate(R.layout.expand_layout, 
          null, false); 
       } 
      }); 
+0

這是一個非常愚蠢的解決方案,我有錯佈局在那裏我只是試圖加快這一點expand_layout.xml假設是expand_child_layout.xml我只是忽略了它,我很抱歉 – thekevshow

+1

如果你認爲它對未來的訪問者有用,你應該發表你的評論作爲答案或者乾脆刪除你的問題。 – Sam

回答

1

「這是一個非常愚蠢的解決方案,我曾在那裏的錯誤佈局我只是想通過這一點。expand_layout.xml以速度爲假設是expand_child_layout.xml