2

i have a listview that contains an custom control
my custom control have progress bar in it and i want change the value of progress bar.

int iRowCount = 0;
    CMessage processMessage = null;
    for (CMessage msg : m_msgList)
    {
        iRowCount ++;
        if(msg._id == iMessageId)
        {
            processMessage = msg;
            break;
        }
    }

    if(processMessage == null)
        return;

    if(!processMessage.MessageType.equals(AttachType.Video.name()))
        if(!processMessage.MessageType.equals(AttachType.Audio.name()))
            return;

    int rowPosition = iRowCount; 
    View v = lstMessage.getChildAt(rowPosition);
    View updateView = lstMessage.getAdapter().getView(rowPosition - 1, v, lstMessage);
    ILSpeechBubble sBubble = (ILSpeechBubble) updateView.findViewById(R.id.iLSpeechBubble1);
    if(sBubble.getMessageId() == iMessageId)
    {
        iProgress = sBubble.getProgress();
        if(iProgress == 100)
            m_Downloading = false;
        else
            iProgress += 1;

        sBubble.SetProgress(iProgress);
        sBubble.postInvalidate();
        updateView.postInvalidate();

    }

with this code i can get the row that must changed the progress value
but i cant refresh the layout and progress not changed in ui
but when i scroll the listview, progress value changed.!
and i'dont want to use notifydatasetchanged().
tnx 4 any help

Saeed-rz
  • 1,435
  • 1
  • 20
  • 38
  • 3
    Why don't you want to use `notifydatasetchanged`? – gunar Jun 19 '13 at 11:14
  • because i dont want refresh whole view – Saeed-rz Jun 19 '13 at 11:33
  • What is the penalty of refreshing the whole view compared to the complexity of maintaining above-alike code? ;) – gunar Jun 19 '13 at 11:43
  • there is more item in listview that maybe contains pic,text,audio,video. dont need more cpu usage? – Saeed-rz Jun 19 '13 at 14:16
  • at the end i use listview.invalidateViews(); ! it similar notifyDatasetchanged() – Saeed-rz Jun 30 '13 at 04:48
  • @Leon_SFS You cannot refresh only single row when you call the notifyDatasetchanged() getview will called and only those view who are visible to the list take cpu usage its not the whole list will refresh. – PiyushMishra Jun 30 '13 at 05:40
  • @PiyushMishra yes i know with notifyDatasetchanged entire listview refresh with data,finally i use invalidateviews to refresh listview without getting data – Saeed-rz Jun 30 '13 at 09:37

2 Answers2

2

You can refresh your row of listview using below code:

 ListView list = getListView();
    int start = list.getFirstVisiblePosition();
    for(int i=start, j=list.getLastVisiblePosition();i<=j;i++)
        if(target==list.getItemAtPosition(i)){
            View view = list.getChildAt(i-start);
            list.getAdapter().getView(i, view, list);
            break;
        }
Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
-2

Use this to clean the adapter:

adapter.items.clear();
Guillermo Merino
  • 3,197
  • 2
  • 17
  • 34