2016-05-23 51 views
1

我在全局添加Row_Cursor_Adapter並在Service_ivr AsyncTask中添加onPostExecute()方法後進行了更改。這是更新的代碼。在AsyncTAsk的setAdapter上出現錯誤?

class Service_ivr extends AsyncTask<String, Void, String> 
    { 

     @Override 
     protected String doInBackground(String... param) 
     { 
      SoapObject request = new SoapObject(NAMESPACE ,METHOD_NAME); 
      request.addProperty("user_id",param[0]); 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope.bodyOut=request; 
      envelope.dotNet =true; 
      envelope.setOutputSoapObject(request); 

      try 
      { 
       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       SoapObject obj2 = (SoapObject)envelope.getResponse(); 
       int count = obj2.getPropertyCount(); 
       index = count/7; 
       final lead_content_IVR [] total_ivr_data = new lead_content_IVR[index]; 
       for(int i=0; i<index ;i++) 
       { 
        String call_duration; 
        String lead_id = obj2.getPropertyAsString(i*7+0); 
        String lead_call_from = obj2.getPropertyAsString(i*7+1); 
        String lead_call_to = obj2.getPropertyAsString(i*7+2); 
        String lead_date=obj2.getPropertyAsString(i*7+3); 
        String lead_audio=obj2.getPropertyAsString(i*7+4); 
        String assign_id = obj2.getPropertyAsString(i*7+5); 
        String time = obj2.getPropertyAsString(i*7+6); 
        if(lead_call_from.equals("Welcome Sound") || lead_call_from.equals("Call Missed") || lead_call_from.equals("User Disconnected") || lead_call_from.equals("Customer Missed")) 
        { 
         call_duration= "5 sec"; 
        } 
        else 
        { 
         call_duration = time.toString().concat(" sec"); 
        } 

        total_ivr_data[i] = new lead_content_IVR(lead_id,lead_call_from,lead_call_to,lead_date,lead_audio,assign_id,call_duration); 
       } 

       adapter = new RowCursorAdapter_IVR(Activity_IVR_Lead.this, R.layout.listview_layout_ivr,total_ivr_data); 





      }catch(Exception e) 
      { 
       e.printStackTrace(); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(String s) { 
      super.onPostExecute(s); 
      listView.setAdapter(adapter); 
     } 
    } 

由於你建議我更新代碼,但錯誤始終是一樣的。

+0

移動'listView.setAdapter(適配器);'onPostExecute方法 –

+0

感謝快速反應內線... – Manish

+0

無法解析符號 – Manish

回答

0

更改喜歡你的方法,以便

class service_ivr extends AsyncTask<String, Void, String> 
{ 
    @Override 
    protected lead_content_IVR[] doInBackground(String... param) 
    { 
     SoapObject request = new SoapObject(NAMESPACE ,METHOD_NAME); 
     request.addProperty("user_id",param[0]); 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.bodyOut=request; 
     envelope.dotNet =true; 
     envelope.setOutputSoapObject(request); 
     lead_content_IVR [] total_ivr_data = null; 
     try 
     { 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
      androidHttpTransport.call(SOAP_ACTION, envelope); 
      SoapObject obj2 = (SoapObject)envelope.getResponse(); 
      int count = obj2.getPropertyCount(); 
      index = count/7; 
      total_ivr_data = new lead_content_IVR[index]; 
      for(int i=0; i<index ;i++) 
      { 
       String call_duration; 
       String lead_id = obj2.getPropertyAsString(i*7+0); 
       String lead_call_from = obj2.getPropertyAsString(i*7+1); 
       String lead_call_to = obj2.getPropertyAsString(i*7+2); 
       String lead_date=obj2.getPropertyAsString(i*7+3); 
       String lead_audio=obj2.getPropertyAsString(i*7+4); 
       String assign_id = obj2.getPropertyAsString(i*7+5); 
       String time = obj2.getPropertyAsString(i*7+6); 
       if(lead_call_from.equals("Welcome Sound") || lead_call_from.equals("Call Missed") || lead_call_from.equals("User Disconnected") || lead_call_from.equals("Customer Missed")) 
       { 
        call_duration= "5 sec"; 
       } 
       else 
       { 
        call_duration = time.toString().concat(" sec"); 
       } 

       total_ivr_data[i] = new lead_content_IVR(lead_id,lead_call_from,lead_call_to,lead_date,lead_audio,assign_id,call_duration); 
      } 
     }catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 
     return total_ivr_data; 
    } 

    public void onPostExecute(lead_content_IVR [] total_ivr_data) { 
     RowCursorAdapter_IVR adapter = new RowCursorAdapter_IVR(Activity_IVR_Lead.this, R.layout.listview_layout_ivr,total_ivr_data); 
     listView.setAdapter(adapter); 
    } 
}