1

In single top mode activity, I am successfully getting data using asynctask but I am unable to load data into ListView. Same code working in onCreateView. I am using Android Search widget.

This is my onNewIntent Method:

@Override
protected void onNewIntent(Intent intent) {

    //intent.putStringArrayListExtra("alist", alist);

     setIntent(intent);

    ArrayList<RowItem> rowItems = new ArrayList<RowItem>();



    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
          String query = intent.getStringExtra(SearchManager.QUERY);

          alist.add(query);
        //  listView = (ListView) findViewById(R.id.listView1);

          GetJson gj  =   new GetJson(this,rowItems);
         gj.delegate = this;
         gj.execute(query);



         CustomListViewAdapter adapt = new CustomListViewAdapter(this,
                    R.layout.list_item, rowItems);

            listView.setAdapter(adapt);


    }


}




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main); 

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }           
    ArrayList<RowItem> rowItems = new ArrayList<RowItem>();
    listView = (ListView) findViewById(R.id.listView1);

      GetJson gj  =   new GetJson(this,rowItems);
     gj.delegate = this;
     gj.execute("travel");



     CustomListViewAdapter adapt = new CustomListViewAdapter(this,
                R.layout.list_item, rowItems);

        listView.setAdapter(adapt);



}

these results generated by oncreate method

onintent generating blank listview

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
chandra mohan
  • 327
  • 1
  • 4
  • 19
  • Is gj.execute() symchronous? – nyarlathotep77 Jun 14 '14 at 08:17
  • @nyarlathotep77 hmm gj is subclass of asynctask – chandra mohan Jun 14 '14 at 08:45
  • So you should set your adapter with the data in the callback called by the asynctask. You are treating execute() as a synchronous call which is wrong. You should set the adapter with the data retrieved by the AsyncTask in onPostExecute(). Where is your implementation of that method? – nyarlathotep77 Jun 14 '14 at 11:29
  • @nyarlathotep77 I am getting data by rowitems not by adapter. I think i should try like u said . but why it is working for oncreate method – chandra mohan Jun 14 '14 at 11:45
  • @nyarlathotep77 I am setting data retrieved by onPostExecute method only – chandra mohan Jun 14 '14 at 11:53
  • I didn't mean getting data through an adapter as that's not its purpose. I said set your adapter with data in the onPostExecute() because that's the callback from your asynctask telling you that loading the data has completed. – nyarlathotep77 Jun 14 '14 at 12:43

0 Answers0