Ich muss LinearLayouts dynamisch nach einer Entity List erstellen. Die Layouts werden ohne Probleme gezeichnet. Mein Problem ist, wenn ich versuche zu erkennen, auf welches Layout ich geklickt habe, da immer auf das letzte verwiesen wird.Anklickbares lineares Layout dynamisch erstellen
Der Code ist so etwas wie dieses:
LinearLayout llProducts = FindViewById<LinearLayout>(Resource.Id.llProducts);
LinearLayout llNewProduct;
int i = 0;
foreach(Product p in productsList)
{
llNewProduct = new LinearLayout(this);
llNewProduct.Clickable = true;
llNewProduct.Id = i++;
TextView txtProduct = new TextView(this);
txtProduct.Text = p.Name;
llNewProduct.AddView(txtProduct);
llProducts.AddView(llNewProduct);
llNewProduct.Click += (sender, e)
{
//This always shows the last Id
Toast.MakeText(this, llNewProduct.Id.ToString(), ToastLength.Short).Show();
}
}
ich etwas Hilfe zu schätzen wissen. Danke
Woher kommt es? 'LlNewProduct.Clickable = true;'? – waqaslam