2012-09-24 22 views
5

मैंने एक पेड़ को दो विस्तारणीय सूची दृश्य के रूप में बनाया है, उन वस्तुओं में से एक जिनमें बहुत से बच्चे हैं (15) दूसरों के मुकाबले ज्यादा, उनके सभी बच्चे नहीं दिखाते हैं।यदि सूची बहुत बड़ी है तो एंड्रॉइड डबल विस्तार योग्य सूचीदृश्य आइटम छुपाता है

_ ______ 
+|_______| 
    _______ 
    +|_______| 
     _______ 
     |_______| 
     _______ 
     |_______| 
      ... 
      ... 
     _______ 
     |_______| // 11-th item 
     _______ // 12-th item can be seen a little and it-s clickable 
    _______ 
    +|_______| 
    _______ 
    +|_______| 
    ... 
    ... 
    _______ 
    +|_______| 

12 वीं आइटम के बाद सूची में कटौती की जाती है। मैंने सूची के आकार पर कोई बाधा नहीं डाली है। कोई विचार क्यों ऐसा होता है? धन्यवाद!

EDIT यह एफआईआर विस्तार योग्य सूची के लिए कोड है।

<ExpandableListView android:layout_width="fill_parent" android:id="@+id/ParentLevel" 
       android:groupIndicator="@null" android:choiceMode="singleChoice" 
       android:layout_height="fill_parent" 
       android:layout_above="@id/button_layout" 
       android:paddingRight="5dp"> 

अन्य sublist एडाप्टर getView() विधि में जुड़ जाते हैं।

कोड उदाहरण

//MainActivity.java 
public class MainActivity extends Activity implements OnChildClickListener { 

ExpandableListView elv; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // QUI SOTTO 
    Tree root = new Tree("root", 123); 

    for (int i = 0; i < 3; i++) { 
     Tree firstLevel = new Tree(("firstLevel" + i), i); 

     for (int j = 0; j < 6; j++) { 
      Tree secondLevel = new Tree("secondLevel" + j, j); 

      for (int z = 0; z < 27; z++) { 
       Tree thirdLevel = new Tree("thirdLevel" + z, z); 

       secondLevel.addChild(thirdLevel); 
      } 

      firstLevel.addChild(secondlevel); 
     } 

     root.addChild(firstLevel); 
    } 


    elv = new ExpandableListView(this); 
    final TreeAdapter treeAdapter = new TreeAdapter(this, root, this); 
    elv.setAdapter(treeAdapter); 
    elv.setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE); 

    elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { 

     @Override 
     public boolean onGroupClick(ExpandableListView parent, View v, 
       int groupPosition, long id) { 

      for (int i = 0; i < treeAdapter.getGroupCount(); i++) { 
       elv.collapseGroup(i); 
      } 

      elv.expandGroup(groupPosition); 
      return true; 
     } 
    }); 

    setContentView(elv); 
    elv.expandGroup(0); 

    Entry e = treeAdapter.lsfirst[0]; 

    e.cls.expandGroup(1); 

    treeAdapter.selectedClass = 33; 

} 

TreeAdapter.java

public class TreeAdapter extends BaseExpandableListAdapter { 

final static String TAG = TreeAdapter.class.getSimpleName(); 


static public Integer selectedClass = null; 

static int CHILD_PADDING; 
static float TEXT_SIZE; 


private Tree tree; 

private OnChildClickListener lst; 

final private Context context; 


class Entry{ 
    final CustExpListview cls; 
    final SecondLevelAdapter sadtp; 
    public Entry(CustExpListview cls, SecondLevelAdapter sadtp) { 
     this.cls = cls; 
     this.sadtp = sadtp; 
    } 
} 

Entry[] lsfirst; 


public TreeAdapter(MainActivity ctx, Tree tree, OnChildClickListener lst){ 
    this.context = ctx; 
    this.tree = tree;  
    this.lst = lst; 
    TEXT_SIZE = 35; 
    CHILD_PADDING = 40; 

    lsfirst = new Entry[tree.getChilds().size()]; 

    for(int i=0; i<tree.getChilds().size();i++){ 
      CustExpListview SecondLevelexplv = new CustExpListview(context); 
      SecondLevelAdapter adp = new  
         SecondLevelAdapter(tree.getChilds().get(i)); 
      SecondLevelexplv.setAdapter(adp); 
      SecondLevelexplv.setGroupIndicator(null); 
      SecondLevelexplv.setOnChildClickListener(lst);// add listener 

      lsfirst[i] = new Entry(SecondLevelexplv, adp); 

    } 


} 



    @Override 
    public Object getChild(int arg0, int arg1){    
      return arg1; 
    } 

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

    @Override 
    public View getChildView(int groupPosition, int childPosition, 
          boolean isLastChild, View convertView, ViewGroup parent){ 
     //LISTA DI secondlevel   
     return lsfirst[groupPosition].cls; 
    } 

    @Override 
    public int getChildrenCount(int groupPosition){ 
    return 1; 
    } 

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

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

    @Override 
    public long getGroupId(int groupPosition) { 

    return tree.getChilds().get(groupPosition).getId(); 
    } 

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

     //firstlevel 

    TextView tv = new TextView(context); 
    tv.setText(tree.getChilds().get(groupPosition).getName()); 
    tv.setPadding(3, 7, 7, 7); 

    return tv; 
    } 

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

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


    ///////////////////////////////////////////////////////////////////////////// 

    //_____________-------------________----------________---------_______-----// 

    ///////////////////////////////////////////////////////////////////////////// 


    public class CustExpListview extends ExpandableListView{ 

      int intGroupPosition, intChildPosition, intGroupid; 

      public CustExpListview(Context context) 
      { 
      super(context); 

      this.setSelector(R.drawable.divider_gray); 

      } 

      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
      { 
      widthMeasureSpec = MeasureSpec.makeMeasureSpec(960, MeasureSpec.AT_MOST); 
      heightMeasureSpec = MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST); 
      super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
      } 
      } 

      public class SecondLevelAdapter extends BaseExpandableListAdapter{ 

       Tree tree2; 
       public SecondLevelAdapter(Tree tr) { 
        this.tree2 = tr; 
       } 

        //Returns the id of the selected class 
        @Override 
        public Object getChild(int groupPosition, int childPosition) {     
    return tree2.getChilds().get(groupPosition).getChilds().get(childPosition).getId(); 
        } 

        @Override 
        public long getChildId(int groupPosition, int childPosition) { 
         return tree2.getChilds().get(groupPosition).getChilds().get(childPosition).getId(); 
        } 

        @Override 
        public View getChildView(int groupPosition, int childPosition, 
              boolean isLastChild, View convertView, ViewGroup parent) { 
         //thirdlevel 
         TextView tv = new TextView(context); 
         tv.setText(tree2.getChilds().get(groupPosition).getChilds().get(childPosition).getName()); 

         if(selectedClass!=null && selectedClass ==tree2.getChilds().get(groupPosition).getChilds().get(childPosition).getId()){ 
          tv.setBackgroundResource(R.drawable.divider_gray); 

         } 
         tv.setPadding(2*CHILD_PADDING, 5, 300, 5); 

        return tv; 
        } 

        @Override 
        public int getChildrenCount(int groupPosition){ 
        return tree2.getChilds().get(groupPosition).getChilds().size(); 
        } 

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

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

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

        @Override 
        public View getGroupView(int groupPosition, boolean isExpanded, 
        View convertView, ViewGroup parent) 
        {// secondlevel 
        TextView tv = new TextView(context); 
        tv.setText(tree2.getChilds().get(groupPosition).getName()); 
        tv.setPadding(CHILD_PADDING, 7, 200, 7); 

        return tv; 
        } 

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

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

    } 

} 

Tree.java

public final class Tree { 

final static String TAG=Tree.class.getSimpleName(); 

final private String name; 
final private int id; 

private Tree parent; 
private LinkedList<Tree> childs = new LinkedList<Tree>(); 


public Tree(String name, int id) { 
    parent = null; 
    this.name = name; 
    this.id = id; 
} 

public void addChild(Tree child){ 
    child.parent = this; 
    childs.add(child); 
} 


public int getId() { 
    return id; 
} 

public String getName() { 
    return name; 
} 

public Tree getParent() { 
    return parent; 
} 

public LinkedList<Tree> getChilds() { 
    return childs; 
} 



@Override 
public String toString() { 
    Iterator<Tree> iter = childs.iterator(); 
    String childs = "["; 
    while(iter.hasNext()){ 
     Tree ch = iter.next(); 
     childs = childs.concat(ch+","); 
    } 
    childs = childs.concat("]"); 
    return name + " "+ id + childs; 
} 


} 
+0

क्या आप अपनी लेआउट एक्सएमएल फाइलों को साझा कर सकते हैं? धन्यवाद। – UgglyNoodle

+0

हाय, मैंने कोड जोड़ा, अगर आप कोशिश कर सकते हैं और क्या देखते हैं, तो इसे 26 बच्चों को दिखाना है, लेकिन यह केवल 21 दिखाता है और दूसरे स्तर के अन्य सभी बच्चों को गायब कर देता है ... मैं इस व्यवहार को समझ नहीं पा रहा हूं ... धन्यवाद – linnal

उत्तर

1

मैं अपने कोड का परीक्षण नहीं किया है, लेकिन की onMeasure() विधि को देख आपका CustExpListview, मैं देखता हूं कि आपने अधिकतम चौड़ाई और ऊंचाई निर्दिष्ट की है। यदि आप अधिकतम ऊंचाई हटाते हैं, तो यह सभी बच्चों को फिट करने में सक्षम होना चाहिए।

+0

बहुत बहुत धन्यवाद! मैंने कोड के उस हिस्से को नहीं देखा: \ – linnal

+0

@ery ur मुद्दा हल किया गया था या नहीं, मुझे भी एक ही समस्या का सामना करना पड़ रहा है – sri

+0

@sri हां, यह उपरोक्त बताए गए मेजर() विधि की समस्या थी – linnal