Search code examples
androidjsonmodel-view-controllerandroid-sdk-manager

how to get the result in onPostExecute method


I am trying to fetch the getcontent() method from model but when i am trying to fetch the method it shows null value .

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


    }
}

Solution

  • Check this

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