How to update a view item in a listview on an event

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to update a view item in a listview on an event

Postby Tinky » Tue Dec 23, 2008 7:50 am

Hi,

I am working on a listview with customized list adapter, in which i have progress bar in each list item, and those progress bar should increment as par the service result (service downloads some file from network and returns progress of download).. but the problem which i am facing is i am not able to get the reference of individual progress bar to set its progress.. so the question is which is the best way to update a particular view item in a list on an event.. even i could not found any of such example in APIDemos..

Could anyone please suggest me any solution on this, or the best or recommended way to update a view item in a list on an event.

Right now what i am doing is, i am keeping references of views in a Map<String listId, Object view> and on an event i recognize from key which progressbar to update and then using the stored object from Map regenerating an object of a ProgressBar and then setting the progress of a particular progress bar.
But because of this when i try to update (suppose)first progressbar with its stored reference then 8th progressbar which is currently out off focus gets update... and we come to know this when focus goes to that list item and the first list item goes out of focus, as the first view object gets reuse when it goes out of focus for the next viewitem in the list, currently its 8th listview item

My code is

public class CustomCursorAdapter extends SimpleCursorAdapter
{
private Map<String, Object> mViewInfo = new HashMap<String, Object>();
........
public void bindView(View view, Context context, Cursor cursor)
{
...........
mViewInfo.put(rowId, view);
..........
}
......
public void setProgress(String rowId, int totalSize, int downloadedSize) {
int progress = mCurrentProgress = (downloadedSize*100)/totalSize;
View mView = (View)mViewInfo.get(rowId);
ProgressBar mProgressBar = (ProgressBar)mView.findViewById(R.id.progressbar);
mProgressBar.setProgress(progress);
}
........
}

Thanks in advance
Tinky
Tinky
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Sep 09, 2008 9:18 am
Location: India

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests