Formatting ListView Content During onCreate() method (getting ListView children)

女生的网名这么多〃 提交于 2020-01-16 18:27:47

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/5358270/formatting-listview-content-during-oncreate-method-getting-listview-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!