How to update listview after calling Asynctask to call webservice

前端 未结 3 1517
死守一世寂寞
死守一世寂寞 2021-01-03 12:30

I am calling a webservice through asynctask, to call the webservice i am calling one method named makeRequest() in

相关标签:
3条回答
  • 2021-01-03 13:26

    call the success method on onPostExecute method

    0 讨论(0)
  • 2021-01-03 13:30

    Since this the error that comes up when you do some MainThread task in another thread.....

    try This:

    runOnUiThread(new Runnable(){
    
    public void run(){
    
         this.adapter.setList(list);
         this.adapter.notifyDataSetChanged();
       }
    
    });
    

    This code might have some errors But in simple Words.. add the notifyDataSetChanged call into runOnUiThread() method. You will be Done..

    OR this can also be DOne ( the perfect way )

    add the following in your activity class

     private Handler handler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
    
            this.adapter.setList(list);
            adapter.setnotifyDataSetChanged();
         }
      };
    

    Call this handler when and where you want to call the notifydatasetchanged like this

      handler.sendEmptyMessage(0);
    

    Thanks sHaH

    0 讨论(0)
  • 2021-01-03 13:31

    You should update your List like this.

    Activity_name.this.runOnUiThread(new Runnable() {
    
    @Override
    public void run() {
          list = (ArrayList<Map<String, String>>) result;
          this.adapter.setList(list);
          this.adapter.notifyDataSetChanged();
        }
    });
    
    0 讨论(0)
提交回复
热议问题