开发者

I Want to display a listview when i click a button in Monodroid. i tried this coding. its not running. Can anyone correct this

开发者 https://www.devze.com 2023-03-15 09:06 出处:网络
I want to display a listview when I click a button in Monodroid. I tried the following code, however it doesn\'t run. Can anyone correct this?

I want to display a listview when I click a button in Monodroid. I tried the following code, however it doesn't run. Can anyone correct this?

protected override void OnCreate (Bundle bundle)

{

base.OnCreate (bundle);

SetContentView (Resource.Layout.Main);

Button button1 = FindViewById<Button> (Resource.Id.btn);

button1.Click += delegate { listviewFunction(); };

}

pub开发者_高级运维lic void listviewFunction()

{

 ListAdapter = new ArrayAdapter<string>(this, Resource.Layout.list_item, _countries);

 ListView.TextFilterEnabled = true;

 ListView.ItemClick += (sender, args) => Toast.MakeText(Application, ((TextView) args.View).Text, ToastLength.Short).Show();

}


Try just:

button1.Click += ...


Declare a ListView globally:

private ListView _listView;

Now (1)create the ListView, OR (2)get it from a axml file:

(1)

_listView = new ListView(this);

(2)

_listView = (ListView)View.FindViewById(Resource.Id.MyList);

Now create your adapter, then:

_listView.SetAdapter(myAdapter);

Then create your ItemClick handler:

_listView.ItemClick += (sender, args) => Toast.MakeText(Application, ((TextView) args.View).Text, ToastLength.Short).Show();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号