格式化的ListView内容onCreate()方法在(获得的ListView子女) [英] Formatting ListView Content During onCreate() method (getting ListView children)

查看:247
本文介绍了格式化的ListView内容onCreate()方法在(获得的ListView子女)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的从数据库填补了ListActivity。

根据一个存储在欲行在ListView格式化记录信息。例如,我有一个布尔coulmn它指定是否当前条目已被划分出,如果是的话我想设置删除线格式标记的列表行内textViews之一。

我认为我可以做到这一点的方法是从ListActivity获取ListView控件,然后让我想要使用getChildAt()方法,然后充气,并根据需要格式化视图更改视图。然而,在这一点上有没有孩子的对象,我无法找到另一种方式来获得个人的看法。

我现在正在尝试以下code,但我想要两个文本的意见膨胀回来为空。在code是一个内部类ShoppingList这是ListActivity所以它可能蹊跷的是我打电话getView()方法的方式中。

 的for(int i = 0; I< adapter.getCount();我++)
             {
                 视图thisView = adapter.getView(也就是,ShoppingList.this.getListView()getRootView(),ShoppingList.this.getListView());
                //膨胀意见
                TextView的view_item_name =(TextView中)thisView.findViewById(R.id.view_item_name);
                TextView的view_item_checked =(TextView中)thisView.findViewById(R.id.view_item_checked);
             }


解决方案

这是适配器是什么。 :)你的适配器的 getView 方法(或者如果你有一个的CursorAdapter NewView的和 bindView )是你应该格式化为基于数据项的观点被presented在显示之前名单。

I am using a ListActivity which fills from a database.

Depending on a the information stored in the record I want to format the row in the listView. For example, I have a boolean coulmn which specifies whether the current entry has been 'marked off' and if so then I want to set the strike-through formatting flag on one of the textViews inside the list row.

The way I thought that I could do this was by getting the ListView from the ListActivity and then getting the view that I wanted to change by using the getChildAt() method and then inflating and formatting the view as required. However at this point there are no children in the object and I cannot find another way to acquire the individual views.

I'm trying the following code now but the two text views that I'm trying to inflate come back as null. The code is within an inner class of 'ShoppingList' which is the ListActivity so it's probably something wrong with the way that I'm calling the getView() method.

for (int i = 0; i < adapter.getCount(); i++)
             {
                 View thisView = adapter.getView(i, ShoppingList.this.getListView().getRootView(), ShoppingList.this.getListView());
                // inflate views
                TextView view_item_name = (TextView) thisView.findViewById(R.id.view_item_name);
                TextView view_item_checked = (TextView) thisView.findViewById(R.id.view_item_checked);
             }

解决方案

This is what the Adapter is for. :) The getView method of your adapter (or if you're working with a CursorAdapter, newView and bindView) is where you should format the view for an item based on the data being presented before it is shown in the list.

这篇关于格式化的ListView内容onCreate()方法在(获得的ListView子女)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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