1
我需要獲取被點擊的項目的id以將其發送到另一個活動 請注意,我從JSON 獲取項目的信息,任何幫助將不勝感激! 這裏是我的代碼>>>Xamarin android:如何從自定義列表視圖中的項目中獲取信息
類
public class TableItemm
{
public string discription;
public string price;
public int ImageResourceId;
public TableItemm(string discription, string price, int ImageResourceId)
{
this.discription = discription;
this.price = price;
this.ImageResourceId = ImageResourceId;
}
}
適配器
public class THomeScreenAdapter : BaseAdapter<TableItemm>
{
List<TableItemm> items;
Activity context;
public THomeScreenAdapter(Activity context, List<TableItemm> items) : base()
{
this.context = context;
this.items = items;
}
public override long GetItemId(int position)
{
return position;
}
public override TableItemm this[int position]
{
get { return items[position]; }
}
public override int Count
{
get { return items.Count; }
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = items[position];
View view = convertView; // re-use an existing view, if one is available
if (view == null) // otherwise create a new one
view = context.LayoutInflater.Inflate(Resource.Layout.item, null);
view.FindViewById<TextView>(Resource.Id.DText1).Text = item.discription ;
view.FindViewById<TextView>(Resource.Id.PText2).Text = item.price;
view.FindViewById<ImageView>(Resource.Id.Image).SetImageResource(item.ImageResourceId);
return view;
}
}
OnListItemClick
public void OnListItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
var listView = sender as ListView;
// note that >>> List<TableItemm> L2MLIStt;
var t = L2MLIStt[e.Position];
//var t2 = L2MLIStt2[e.Position];
// var t3 = L2MLIStt3[e.Position];
var x = e.Position ;
Android.Widget.Toast.MakeText(this, x, Android.Widget.ToastLength.Long).Show();
// take the item ID & show it in product page
var intent = new Intent(this, typeof(product));
// intent.PutExtra("test", x);
//StartActivity(intent);
}