机器人:在列表视图列表视图 [英] android: listview in listview

查看:144
本文介绍了机器人:在列表视图列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把一个ListViewItem的内部列表视图。内部列表视图不应该是滚动的,但把它需要显示所有它的所有行的大小。有没有更好的方式来这样做呢?表,网格,...?即时朝右现在的问题是,内列表视图不采取所需的空间,因此它切成围绕第一列表项的结束。如果我尝试滚动,只是外部列表视图的滚动,这正是我想要的。

谢谢,我的最终解决方案是

 的LinearLayout布局=(的LinearLayout)row.findViewById(R.id.LLBroadcasts);
layout.removeAllViews();

对于(B项:bs.getItems()){

  查看孩子= _inflater.inflate(R.layout.item_row,NULL);

  TextView的tvTitle =(TextView中)child.findViewById(R.id.TVItemTitle);
  tvTitle.setText(b.getTitle());

  TextView的tvDesc =(TextView中)child.findViewById(R.id.TVItemDescription);
  tvDesc.setText(b.getDescription());
  layout.addView(子);
}
 

解决方案

从Android文档 - 列表视图的ListView是显示滚动项目列表视图组

您真的不希望滚动内心的列表视图中,要滚动的外部列表视图。然而,我asume使得内列表视图可以变化上的元素的数量。

而不是列表视图中,你可以使用

  • 线性布局,看到这的教程还是看<一href="http://stackoverflow.com/questions/6661261/how-to-add-dynamic-content-to-lineary-layout-programmatically-in-my-case">How以编程方式在我的情况下添加动态内容lineary布局?
  • 表格布局,看到这的教程

有关线性布局(一些样本code):

//访问您的线性布局 的LinearLayout布局=(的LinearLayout)findViewById(R.id.layout); //加载你行的XML结构 查看孩子= getLayoutInflater()膨胀(R.layout.row)。 //现在补行,你会与列表视图做 //例如。 (TextView中)child.findViewById(... ... //比添加 layout.addView(子);

更新:
你应该保存在一个视图座线性规划(见查看持有人模式)。我觉得 removeAllViews()是在当前行具有比重复使用1较小的内部行只需要,所以我也保存在视图持有人的行数。

如果内的最大行数不高,你也可以考虑一下缓存他们的观点持有者,以避免膨胀,findByViewId(可以说在一个ArrayList)。

i'm trying to place a listview inside a listviewitem. the inner listview should not be scrollable but take all size it needs to display all it's rows. is there a better way to to this? table, grid, ...? the problem i'm facing right now is that the inner listview doesn't take the space it needs, so it's cut at about the end of the first listitem. if i try to scroll, just the outer listview is scrolling which is exactly what i want.

thanks, my final solution is

LinearLayout layout = (LinearLayout) row.findViewById(R.id.LLBroadcasts);
layout.removeAllViews();

for (Item b : bs.getItems()) {

  View child = _inflater.inflate(R.layout.item_row, null);

  TextView tvTitle = (TextView) child.findViewById(R.id.TVItemTitle);
  tvTitle.setText(b.getTitle());

  TextView tvDesc = (TextView) child.findViewById(R.id.TVItemDescription);
  tvDesc.setText(b.getDescription());
  layout.addView(child);
}

解决方案

From the Android documentation - Listview: ListView is a view group that displays a list of scrollable items

You do not really want to scroll that inner list view, you want to scroll the outer listview. However I asume that the inner listview may vary on the amount of elements.

Instead of the list view you could use a

For the linear layout (some sample code):

// access your linear layout
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
// load the xml structure of your row
View child = getLayoutInflater().inflate(R.layout.row);
// now fill the row as you would do with listview
//e.g. (TextView) child.findViewById(...
...
// and than add it
layout.addView(child);

Update:
You should save the linear layout in a view holder (see View Holder pattern). I think the removeAllViews() is only necessary when the current row has lesser inner rows than the reused one, so I would also save the number of rows in the view holder.

If the maximum number of inner rows is not to high you could also think about caching them in the view holder to avoid the inflate and findByViewId (lets say in an ArrayList).

这篇关于机器人:在列表视图列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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