Horizontal ScrollView in List View Item Android

前端 未结 4 505
庸人自扰
庸人自扰 2020-12-10 18:34

I have a list view with 20 rows and I want to setup a horizontal scrollview for every row item in list view, as each row contains more than one item.

He

4条回答
  •  -上瘾入骨i
    2020-12-10 19:01

    The problem is with your adapter as:

    1. getCount() from your adapter must return the total number from list. Returning 20 is not valid in your context - and you seem to have 20 items in your list. You should return dataSet.size();
    2. getItem() should return the item from the model data structure, in this case:

    Below

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return dataSet.get(position);
    }
    

    Also, your getView method must return the view that displays the model data at given at position parameter. Returning a ViewGroup with non-meaningfull dummy data is what you currently have. You should get the ArrayList from parameter position (through dataSet.get(position)) and construct/inflate a View that displays properly this data structure item.

提交回复
热议问题