本文介绍了设置适配器的LinearLayout,而不是ListView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,需要适应样的数据我收到的布局。我需要这个尽可能通用。所以在我的适配器类的布局需要根据数据动态地修改。
这是我打算这样做。

I am working on a layout that needs to adapt to the kind of data I receive. I need to make this as generic as possible. So the layout in my adapter class needs to be modified dynamically according to the data.This is how I plan to do so.

我的活动XML布局:

<LinearLayout>
  <LinearLayout id="1" ></LinearLayout>
  <LinearLayout id="2" ></LinearLayout>
  <LinearLayout id="3" ></LinearLayout>
  <LinearLayout id="4" ></LinearLayout>
  <LinearLayout id="5" ></LinearLayout>
</LinearLayout>

我有适配器,它填充数据。适配器code
  1.新的充气N1布局
  2.获取活动ID 的LinearLayout 基于适配器项目位置
  3.将N1父的LinearLayout 插槽

I have adapter which populates data. Adapter code 1. Inflate new layout N1 2. Get id of activity LinearLayout based on adapter item position 3. Put N1 in parent LinearLayout Slot

问题。我如何使用静态的LinearLayout 的ListView

Problem. How do I use Static LinearLayout than ListView.

推荐答案

您可以这样做:

LinearLayout holder = new LinearLayout(context);
...
holder.removeAllViews();
for(int i = 0 ; i < adapter.getCount(); i++)
    holder.addView(adapter.getView(i, null, holder));
...

这篇关于设置适配器的LinearLayout,而不是ListView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:06
查看更多