【问题标题】:Selecting ListView item选择 ListView 项目
【发布时间】:2013-03-07 08:40:24
【问题描述】:

我创建了一个包含足球俱乐部的 ListView。我想选择一个项目,它会打开一个包含所选项目信息的新活动。

这是我的列表视图:

base.OnCreate (bundle);
        clubs = new string[] {
            "AC Milan",
            "Borussia Dortmund",
            "Chelsea London",
            "FC Barcelona",
            "Manchester United",
            "Manchester City",
            "Real Madrid"
        };

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

【问题讨论】:

  • 根据您的要求实现 itemClickListener 或 itemSelectListner。

标签: c# android listview xamarin


【解决方案1】:

您需要覆盖 OnListItemClick 以从 ListView 中获取所选项目:

protected override void OnListItemClick(ListView listview, 
                                           View view, int pos, long id)
  {
     var selectedvalue = clubs[pos];
    // start new Activity here....
    var intent = new Intent(this, typeof(Your_Next_Activity));
    intent.PutExtra("selectedvalue", selectedvalue);
    StartActivity(intent);
  }

【讨论】:

    【解决方案2】:
    1. 创建 OnItemClickListener
    2. 获取选中项
    3. 使用详细信息开始新活动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多