开发者

How to Identify a ListViewItem to Update a Single Row

I have a ListView displays information about an object. When I click a ListView Item, I open an Activity that let's me manipulate par开发者_开发百科ameters of the object held in the adapter. These parameters are updated and stored remotely.

When I return to the ListView (via the back button), I want to update the ListView Item that I clicked originally by requesting the parameter values from the remote server.

I am currently doing this up updating the entire ListView by clearing it and rebuilding it.

How do I reference the ListView Item so that I can update the data for that item only?

Thanks, Jason


Just set the data for your adapter and call notifyDatasetChanged. Android only draws the rows that are visible anyway, so it's pretty efficient.


Knowing the position of the view, this can be done.

View singleItemView = myListView.getChildAt(position);
ImageView icn = (ImageView) singleItemView.findViewById(R.id.icn_icon);
ProgressBar prg = (ProgressBar) singleItemView.findViewById(R.id.prg_icon);
icn.setVisibility(View.GONE);
prg.setVisibility(View.VISIBLE);

(EDIT) This doesn't work because the "position" of the View could be changed upon returning from another Activity. After the onResume() fires, getView() is called and the position of the visible ListView Items are numbered starting with 0. So, the ListView items (id and position) become renumbered based on visiblity. As a result, I end up accessing the wrong object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜