is it possible to set adapter to linear layout?

前端 未结 2 1928
面向向阳花
面向向阳花 2021-02-01 17:10

Is it possible to set adapter to a LinearLayout?

I don\'t want to use ListView since I am using ScrollView. so I am using Li

2条回答
  •  -上瘾入骨i
    2021-02-01 17:51

    no you can't. What you can do is inflate the single row, and adding to the LinearLayout. In pseudo code:

      LinearLayout linearLayout = (LinearLayout) findViewById(...);
      LayoutInflater inflater = LayoutInflater.from(this);
      for (item in arrayList) {
         View view  = inflater.inflate(R.layout.row, linearLayout, false); 
         // set item content in view
         linearLayout.addView(view)
      }
    

提交回复
热议问题