是否可以将适配器设置为线性布局? [英] is it possible to set adapter to linear layout?

查看:105
本文介绍了是否可以将适配器设置为线性布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将适配器设置为LinearLayout?

Is it possible to set adapter to a LinearLayout?

我不想使用ListView,因为我正在使用ScrollView. 所以我在用LinearLayout ...

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

我正在动态添加视图,现在我需要使用适配器. 所以有人有什么建议吗?

In that I am dynamically adding views and now I need to use adapter.. so anybody have any suggestions?

我正在这样做...

LinearLayout clientList = (LinearLayout) findViewById(R.id.clients);
adapter = new Sample1AdapterActivity(this, arrayList);
View list = (ListView) getLayoutInflater().inflate(R.layout.user_details, getListView(), false);

推荐答案

不,您不能.您可以做的是将单行膨胀,然后添加到LinearLayout中.用伪代码:

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)
  }

这篇关于是否可以将适配器设置为线性布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆