string[] items = new string[] { "Alternative Rock","Classical"}
lst.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) {
FragmentTransaction fragmentTx=this.FragmentManager.BeginTransaction();
TracksByGenres fragTrack=new TracksByGenres();
//get our item from listview
fragmentTx.Replace(Resource.Id.fragmentContainer,fragTrack,.....);
fragmentTx.AddToBackStack(null);
fragmentTx.Commit();
};
TracksByGenres.cs
public async override void OnActivityCreated(Bundle savedInstancesState)
{
base.OnActivityCreated (savedInstancesState);
// what do I write?
}
如何从Xamarin.Android上的ListView
获取所选项目并创建一个返回旧片段的后退按钮?
答案 0 :(得分:1)
ItemClickEventArgs
Position
会告诉您所选项目的索引
lst.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) {
var selected = items[e.Position];
}
答案 1 :(得分:0)
在OnListItemClick
子类中覆盖public class myListFragment : ListFragment
{
string[] data = { "Alternative Rock","Classical" } ;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
ArrayAdapter adapter = new ArrayAdapter (this,
Resource.Layout.TextViewItem, data);
ListAdapter = adapter;
}
protected override void OnListItemClick (ListView l, View v,
int position, long id)
{
base.OnListItemClick (l, v, position, id);
Toast.MakeText (this, data [position],
ToastLength.Short).Show ();
}
}
以接收点击的项目
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:53453/api/nisperson/addnewconnection'.",
"MessageDetail":"No action was found on the controller 'NISPerson' that matches the request."}
Android.App.ListFragment.OnListItemClick方法
当选择列表中的项目时,将调用此方法。
答案 2 :(得分:0)
只需为ListView.ItemClick
创建一个方法mListView.ItemClick += MListView_ItemClick;
从方法中可以检索点击项目的索引
void MListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
Toast.MakeText(Application.Context, e.Position, ToastLength.Short).Show();
}