Lullan
Lullan

Reputation: 31

Xamarin Android Listview ClickEvent doesn't work

I am pretty new here, but I have problem and hope that you can help me to solve it. I've created a ListView in Xamarin Android, VS 2017. After configuring it I tried to add a click Event in the MainActivity. Unfortunately, after many tries, I recognized that this is not working. So it doesn't recognize if the ListView is clicked. I know that this is a very basic question, so may there is a simple answer or some basic mistakes I#ve made? Thank you very much!

    public class MainActivity : Activity
{
    private ListView Lenseslv;
    private TextView textView1;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.Main);
        Lenseslv = FindViewById<ListView>(Resource.Id.Lenseslv);
        textView1 = FindViewById<TextView>(Resource.Id.textView1);
        Lenseslv.Adapter = new MyCustomListAdapter(UserData.Users);
    }

    public void Lenseslv_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
    {
        textView1.Text = ("ClickEvent");
    }

Upvotes: 0

Views: 50

Answers (1)

Jason
Jason

Reputation: 89214

you have to assign the event handler to your ListView

Lenseslv.ItemClick += Lenseslv_ItemClick

Upvotes: 1

Related Questions