It happens that, after creating a listview in the same way it explains in the documentation, the elements are not loaded, as if there were no elements to be displayed.
I have verified that yes, there are elements in the array of objects, so in theory they should be displayed.
BaseAdapter Code:
public class SelectorScreenAdapter : BaseAdapter<Campeonato>
{
Campeonato[] campeonatos;
Activity context;
public SelectorScreenAdapter(Activity ctx, Campeonato[] items) : base()
{
this.context = ctx;
this.campeonatos = items;
}
public override Campeonato this[int position] {
get
{
return campeonatos[position];
}
}
public override int Count {
get
{
return campeonatos.Count();
}
}
public override long GetItemId(int position)
{
if(campeonatos.Count() > position)
{
return (long)campeonatos[position].ID1;
}
else
{
return -1;
}
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
Campeonato item = campeonatos[position];
if (view == null)
{
view = LayoutInflater.From(context).Inflate(Resource.Layout.customRow, null, false);
}
view.FindViewById<TextView>(Resource.Id.nombreCamp).Text = item.C_nombre;
view.FindViewById<TextView>(Resource.Id.zonaCamp).Text = item.Zona;
view.FindViewById<TextView>(Resource.Id.localidadCamp).Text = item.Localidad;
view.FindViewById<TextView>(Resource.Id.fechaCamp).Text = item.Ic_ano.ToString();
view.FindViewById<TextView>(Resource.Id.categoriaCamp).Text = item.Tipo;
return view;
}
}
Code of the introduction of objects in the list and the relevant event:
public void loadItems(int userINT)
{
logMessage("Loading Items...");
listView = (ListView)FindViewById(Resource.Id.list);
SelectorScreenAdapter selectorScreenAdapter;
model.DatabaseRetrieveCampeonatos(userINT);
selectorScreenAdapter = new SelectorScreenAdapter(this, model.getArrayCampeonatos());
listView.Adapter = selectorScreenAdapter;
logMessage("Items Loaded");
listView.ItemClick += gotoCampeonato;
logMessage("Event Added");
listView.FastScrollEnabled = true;
}
OnCreate Code:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.selector_campeonatos);
this.model = JsonConvert.DeserializeObject<Model>(Intent.GetStringExtra("MODEL"));
loadItems(model.getLogin().GetLicencia());
}
And the Layouts:
selector_campeonatos:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
customRow:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFDAFF7F"
android:padding="8dp">
<LinearLayout
android:id="@+id/Text"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip">
<TextView
android:id="@+id/nombreCamp"
android:text="Nombre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF7F3300"
android:textSize="20dip"
android:textStyle="italic" />
<LinearLayout
android:id="@+id/Text1"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="10dip">
<TextView
android:id="@+id/fechaCamp"
android:text="Fecha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textColor="#FF267F00"
android:paddingLeft="100dip" />
<TextView
android:id="@+id/localidadCamp"
android:text="Localidad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textColor="#FF267F00"
android:paddingLeft="95dip" />
</LinearLayout>
<LinearLayout
android:id="@+id/Text2"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="10dip">
<TextView
android:id="@+id/zonaCamp"
android:text="Zona"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textColor="#FF267F00"
android:paddingLeft="100dip" />
<TextView
android:id="@+id/categoriaCamp"
android:text="Categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textColor="#FF267F00"
android:paddingLeft="100dip" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>