简体   繁体   中英

Clickable listview in c sharp android

So far i have created a listview which shows items from an array. However, i cant figure out how to make these items perform actions. What i want to do is when someone presses 'Arsenal' in the list it opens the arsenal class and so on for the rest of the list. I am new to c sharp and android coding so im sorry if this is simple, Thanks in advance for any help

This is my code so far:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace App
{
[Activity(Label = "PremierLeague")]
public class Test : ListActivity {
    string[] prem;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        prem = new string[] { "Arsenal", "Aston Villa", "Cardiff City", "Chelsea", "Crystal Palace", "Everton", "Fulham", "Hull City", "Liverpool", "Manchester City", "Manchester United", "Newcastle United", "Norwich City", "Southampton", "Stoke City", "Sunderland", "Swansea City", "Tottenham Hotspur", "West Bromwich Albion", "West Ham United" };

        ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, prem);
        }
    }
}

You must override OnListItemClick

protected override void OnListItemClick (ListView l, View v, int position, long id)

{

  base.OnListItemClick (l, v, position, id); 

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM