Hello,
I have this problem with a Custom listview adapter.
I cannot get the object that the adapter refers to because the compiler will not allow me to cast it to its type.
In Java I do so:
ModelloAttivita thisAttivita = (ModelloAttivita) (listAttivita.getItemAtPosition(selectedIndex)); // where listAttivita is a collection of ModelloAttivita
The C# code:
void listAttivita_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { m_SelectedIndex = e.Position; object thisAttivita = listAttivita.GetItemAtPosition (e.Position); Console.WriteLine (thisAttivita); Toast toast = Toast.MakeText (this, "Selected: "+m_SelectedIndex+ " with Id: "+ thisAttivita.ToString(), ToastLength.Short); toast.Show (); } }
thisAttivita is of type ModelAttivita but, if I try to replace "object thisAttivita" with
ModelloAttivita thisAttivita = listAttivita.GetItemAtPosition (e.Position), I get the error "Cannot implicity convert Java.Lang.Object" to "TestDebug.ModelloAttivita"
The same happens with
ModelloAttivita thisAttivita = (ModelloAttivita) listAttivita.GetItemAtPosition (e.Position);
and
ModelloAttivita thisAttivita = (ModelloAttivita) listAttivita.GetItemAtPosition (e.Position); as ModelloAttivita;
How to obtain the object type corresponding to the row that was selected?
Thanks!