Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

how can getdata from api and use fot recyclerview..

$
0
0

hi
i use this code but mpt in mainactivity and i got erorr in recycleradapter in itemcount that :smile: Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object. occurred

` 

public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
{
View view = LayoutInflater.From(container.Context).Inflate(Resource.Layout.pager_item, container, false);
container.AddView(view);

            mRecyclerView = view.FindViewById<RecyclerView>(Resource.Id.recycler);
            mLayoutManager = new LinearLayoutManager(view.Context);
            mRecyclerView.SetLayoutManager(mLayoutManager);
            mclient = new WebClient();
            Url = new Uri("http://www.aashuraian.ir/api/akhbarmashruhs");

            mclient.DownloadDataCompleted += MclientOnDownloadDataCompleted;
            mclient.DownloadDataAsync(Url);
            mAdapter = new RecyclerAdapter(_akhbarMashruhs);
            mRecyclerView.SetAdapter(mAdapter);
            return view;

        }

      public  void MclientOnDownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {

            var json = Encoding.UTF8.GetString(e.Result);
            _akhbarMashruhs = JsonConvert.DeserializeObject<List<AkhbarMashruh>>(json);





        }`

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>