如何获得一个视图这是一个复杂的ListView列视图中? [英] How to get a view which is inside a complex ListView row view?

查看:140
本文介绍了如何获得一个视图这是一个复杂的ListView列视图中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已被填充通过使用适配器包含数据行的一个ListView。
该行布局RelativeLayout的类型,并且包含不同的视图对象,其中一个的ID为@ + ID / bar_fill。

I have a ListView which has been populated by rows containing data using an adapter. The row layout is of "RelativeLayout" type and contains various view objects, the id of one of them is "@+id/bar_fill".

我有一个循环运行在ListView中的所有孩子的,我想得到我上面提到的视图项目。

I have a loop running over all the childs of the ListView, and I want to "get" the view item i mentioned above.

在code,我使用的是:

The code I'm using is:

ListView list = getListView();
int count = list.getCount();
for (int i = 0; i < count; i++) 
{
   RelativeLayout row = (RelativeLayout) list.getChildAt(i);
   View bar = row.findViewById(R.id.bar_fill);         
}

当它到达崩溃的最后一行然而。当我评论出来,并做了

However when it reaches the last line it crashes. When I commented it out and did

System.out.println(findViewById(R.id.bar_fill));

它返回空值。

我在做什么错了?

推荐答案

在将覆盖自定义适配器此功能。

overide this function in custom adapter.

public View getView(int position, View convertView, ViewGroup parent);
View v = convertView;
    if (v == null) {
        LayoutInflater vi = (LayoutInflater) c
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(id, null);
    }

现在一样,如果你想从列表视图行项目一定的TextView再去做这样的:

Now like if you want certain textview from the listview row item then do it like this:

TextView t1 = (TextView) v.findViewById(com.pis.prototype.R.id.TextView01);

T1是你需要的视图现在...:P

t1 is your required view now...:P

这篇关于如何获得一个视图这是一个复杂的ListView列视图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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