I have a custom listview as following code:
listView.Adapter = new HomeScreenAdapter(this, tableItems);
How do i make the screen to show the last item on the listview and not show the start of the list everytime an item is added to the custom listview?
HomeScreenAdapter.cs
namespacetest {
public class HomeScreenAdapter : BaseAdapter<Model.TableItem> {
List<Model.TableItem> items;
Activity context;
public HomeScreenAdapter(Activity context, List<Model.TableItem> items)
: base()
{
this.context = context;
this.items = items;
}
public override long GetItemId(int position)
{
return position;
}
public override Model.TableItem 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;
if (view == null) // no view to re-use, create new
view = context.LayoutInflater.Inflate(Resource.Layout.content_main, null);
view.FindViewById<TextView>(Resource.Id.Text1).Text = item.Heading;
int expiryrangeint = Convert.ToInt32(item.ExpiryRange);
if (expiryrangeint < 30)
view.FindViewById<TextView>(Resource.Id.Text1).SetBackgroundColor(Android.Graphics.Color.Red);
else if(expiryrangeint > 30 && expiryrangeint < 90)
view.FindViewById<TextView>(Resource.Id.Text1).SetBackgroundColor(Android.Graphics.Color.DarkGray);
else if (expiryrangeint > 90 && expiryrangeint < 180)
view.FindViewById<TextView>(Resource.Id.Text1).SetBackgroundColor(Android.Graphics.Color.Yellow);
else
view.FindViewById<TextView>(Resource.Id.Text1).SetBackgroundColor(Android.Graphics.Color.White);
//textview1.SetBackgroundColor(Android.Graphics.Color.Red);
view.FindViewById<TextView>(Resource.Id.Text2).Text = item.SubHeading;
view.FindViewById<TextView>(Resource.Id.Text3).Text=item.SubSubHeading;
return view;
}
}
}