Scott
Scott

Reputation: 41

get text from listview item

I have a listview that stores the result of speech recognition:

voice_list.ItemClick += delegate(object sender, 
    Android.Widget.AdapterView.ItemClickEventArgs args) 
    { 
        Toast.MakeText(this, "test", ToastLength.Long).Show(); 
    };

How I can get the text in the item? For example, when I say "no", it recognizes (now, know, you know....)

Upvotes: 3

Views: 3177

Answers (1)

Cheesebaron
Cheesebaron

Reputation: 24460

The ItemClickEventArgs you have contain a couple of nice properties you can use, one of them is especially very useful Position. This gives you the Position in the ListView of the item you clicked, which corresponds to the same position of the item in your dataset you have passed to the Adapter you are using.

So in your ItemClick event handler you can do:

var item = _adapter.GetItem(args.Position);

You will probably have to cast the item afterwards.

Upvotes: 1

Related Questions