Android 如何在onPostExecute方法中获得结果

Android 如何在onPostExecute方法中获得结果,android,json,model-view-controller,android-sdk-manager,Android,Json,Model View Controller,Android Sdk Manager,我试图从模型中获取getcontent()方法,但当我试图获取该方法时,它显示空值 public class Gettingcomment extends AsyncTask<String,String,List<CommentModel>>{ @Override protected List<CommentModel> doInBackground(String... params) { String commentur

我试图从模型中获取getcontent()方法,但当我试图获取该方法时,它显示空值

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();


    }
}
public类Gettingcomment扩展异步任务{
@凌驾
受保护列表doInBackground(字符串…参数){
字符串commenturl=params[0];
Populatecomments Populatecomments=新的Populatecomments();
//getCommentModelList(commenturl+mytrendinid);
Log.i(“mytrendin”,commenturl);
列表模型=populatecomments.getCommentModelList(commenturl);
收益模型;
}
@凌驾
受保护的void onPostExecute(列出结果){
super.onPostExecute(结果);
CommentModel CommentModel=新CommentModel();
String content=commentModel.getContent();
Toast.makeText(getApplicationContext(),content,Toast.LENGTH_LONG.show();
}
}
检查此项

 @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();
      }
    }
}
@覆盖
受保护的void onPostExecute(列出结果){
super.onPostExecute(结果);
如果(results.size()>0){

对于(int i=0;i您正在尝试从新创建的CommentModel实例中获取内容,该实例没有任何内容。因此,请从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();
    }
}
public类Gettingcomment扩展异步任务{
@凌驾
受保护列表doInBackground(字符串…参数){
字符串commenturl=params[0];
Populatecomments Populatecomments=新的Populatecomments();
//getCommentModelList(commenturl+mytrendinid);
Log.i(“mytrendin”,commenturl);
列表模型=populatecomments.getCommentModelList(commenturl);
收益模型;
}
@凌驾
受保护的void onPostExecute(列出结果){
super.onPostExecute(结果);
if(results!=null&&results.size()>0){
//这里我从CommentModel列表的0位置获取getContent,您可以循环获取所有模型的内容
String content=results.get(0.getContent();
Toast.makeText(getApplicationContext(),content,Toast.LENGTH_LONG.show();
}
}

}

这是个糟糕的问题吗?有人投了反对票。