0

我的列表。ItemClick:

lstText.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args) 
{
    var userIdTextView = FindViewById<TextView>(Resource.Id.txtUserId);
    var fetchUserId = userIdTextView.Text;

    sUserId = fetchUserId;

    Toast.MakeText(this, sUserId, ToastLength.Short).Show();

};

在列表视图中(Resource.Id.txtUserId),每个列表项都不同。当我单击 toast 时,它总是从列表中的第一项传递相同的值。我该如何解决?

请提供解决方案或提示

4

1 回答 1

1

FindViewById应该用于在列表视图上下文中的每个项目的上下文中查找资源 id,即args.View.

lstText.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args) 
{
    var userIdTextView = args.View.FindViewById<TextView>(Resource.Id.txtUserId);
    var fetchUserId = userIdTextView.Text;

    sUserId = fetchUserId;

    Toast.MakeText(this, sUserId, ToastLength.Short).Show();

};
于 2013-01-09T18:33:54.527 回答