2017-01-20 18 views
-1

我想從模型中獲取getcontent()方法,但是當我試圖獲取它顯示空值的方法時。如何在onPostExecute方法中獲得結果

public class Gettingcomment extends AsyncTask<String,String,List<CommentModel>>{ 


    @Override 
    protected List<CommentModel> doInBackground(String... params) { 

     String commenturl = params[0]; 

     Populatecomments populatecomments =new Populatecomments(); 
     // populatecomments.getCommentModelList(commenturl+mytrendinid); 

     Log.i("mytrendin",commenturl); 

     List<CommentModel> model= populatecomments.getCommentModelList(commenturl); 

     return model; 
    } 

    @Override 
    protected void onPostExecute(List<CommentModel> results) { 
     super.onPostExecute(results); 
     CommentModel commentModel = new CommentModel(); 
     String content = commentModel.getContent(); 
     Toast.makeText(getApplicationContext(),content,Toast.LENGTH_LONG).show(); 


    } 
} 
+0

這是窮人的問題?有人投反對票。 –

回答

2

入住這

@Override 
protected void onPostExecute(List<CommentModel> results) { 
    super.onPostExecute(results); 
    if(results.size()>0){ 
    for(int i=0;i<results.size();i++){ 
     CommentModel commentModel = results.get(i); 
     String content = commentModel.getContent(); 
     Toast.makeText(getApplicationContext(),content,Toast.LENGTH_LONG).show(); 
     } 
    } 
} 
+0

謝謝!!!完成:) –

1

你是從哪個沒有任何內容的新創建CommentModel實例努力的getContent。所以請從doinBackground結果中檢查。

public class Gettingcomment extends AsyncTask<String,String,List<CommentModel>>{ 


@Override 
protected List<CommentModel> doInBackground(String... params) { 

    String commenturl = params[0]; 

    Populatecomments populatecomments =new Populatecomments(); 
    // populatecomments.getCommentModelList(commenturl+mytrendinid); 

    Log.i("mytrendin",commenturl); 

    List<CommentModel> model= populatecomments.getCommentModelList(commenturl); 

    return model; 
} 

@Override 
protected void onPostExecute(List<CommentModel> results) { 
    super.onPostExecute(results); 
    if(results!=null && results.size()>0){ 
    //here i am getting getContent from 0 position of CommentModel list you can loop to get all the model's content 
    String content = results.get(0).getContent(); 
    Toast.makeText(getApplicationContext(),content,Toast.LENGTH_LONG).show(); 
    } 
} 

}

相關問題