android set listview height dynamically

前端 未结 4 1336
情话喂你
情话喂你 2021-01-02 23:39

i have ExpandableListview inside ScrollView and i know that\'s not good but i had too, the only solution to show the whole list is by set its heigh

4条回答
  •  执笔经年
    2021-01-02 23:57

    Your ListView is effectively unneeded in this case. You can as well loop over your adapter's items and just add them to a vertical LinearLayout inside your ScrollView.

    In case you do not want to change a lot of code:

    Replace ListView.setAdapter with

    LinearLayout ll; //this should be the vertical LinearLayout that you substituted the listview with
    for(int i=0;i

    If you already use an OnItemClickListener add after View v = adapter.getView(position, null, null); the following

    final int position = i;
    v.setOnClickListener(new OnClickListener() {
        public onClick(View v) {
            yourOnItemClickListener.onItemClick(null, v, position, 0);
        }
    });
    

    In this case you do not have to worry about any miscalculation in the height.

提交回复
热议问题