Forum Xamarin.Android

Click event in adapter

rajveerrajveer USMember ✭✭
edited October 2015 in Xamarin.Android

I'm trying to add click event in the BaseAdapter , but unfortunately it get call to GetView() multiple times. My code in GetView() is like

List<ShowLinks> items; var download = view.FindViewById (Resource.Id.imageview1) as ImageView; download.Click += (object sender, EventArgs e) =>{ string url = "http:"+items [position].LinkUrl; WebClient WC= new WebClient(); WC.DownloadStringAsync(new Uri(url)); };

Then my click event repeats for all the items in the List, but my requirement is it should accept only selected item.

Posts

  • BerayBentesenBerayBentesen TRUniversity ✭✭✭✭

    re-define your ListView inside OnCreate and when you write YourListViewName.ItemClick += you will see click methods.

  • rajveerrajveer USMember ✭✭

    Thanks @ashalva & @BerayBentesen finally it works by using

    private void ListItemClicked(object sender, AdapterView.ItemClickEventArgs e) { //you can get the item with the position var item = myList[e]; }

Sign In or Register to comment.