Confused with Parse async method of retrieving data

Im trying to retrieve a simple query on parse and add the content on a custom adapter but i can figure it how, i see from the documentation that only with async i can get the data, but how i can add the data after to the adapter if the async method always return void? This is what im trying and is not working

public class BusinessListFragment : Fragment
        List<Business> _list;
        ListView businessListView;

        public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            var view = inflater.Inflate(Resource.Layout.BusinessList, container, false);
            businessListView = view.FindViewById<ListView>(Resource.Id.businessListView);
            _list = new List<Business>();
            Task task = new Task(GetData);
            var adapter = new BusinessListAdapter(Activity, _list);
            businessListView.Adapter = adapter;
            adapter.NotifyDataSetChanged ();

            return view;
        public async void GetData(){
            var query = ParseObject.GetQuery("Business");
            IEnumerable<ParseObject> results = await query.FindAsync();
            var _business = new Business();
            foreach (var temp in results)
                // This does not require a network access.
                _business.Name = temp.Get<string>("name");
                _business.Address = temp.Get<string>("address");
                _business.Town = temp.Get<string>("town");
                _business.Country = temp.Get<string>("country");
                _list.Add (_business);


What am i doing wrong? It should be something pretty simple



  • ChristopherDrososChristopherDrosos GRMember ✭✭
    edited September 2015

    Thanks for this code, i will try it right away, im curious if ContinueWith is indeed needed because we call the data with await, doesnt this ensure that data will surely be loaded? I have problem loading the data on the adapter on OnCreateView not in retrieving the data, i think the RunOnUi part and the recreation of the adapter there will do the trick.
    You rock, it works

Sign In or Register to comment.