我有一个自定义列表视图,如下代码:
listView.Adapter = new HomeScreenAdapter(this, tableItems);
我如何使屏幕显示列表视图中的最后一个项目,而不是每次将项目添加到自定义列表视图时都不显示列表的开始?
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;
}
}
}
答案 0 :(得分:0)
如果数据库已更改,则需要重写在现有应用程序上完成的排序。
此外,您需要更新应用程序。
参考文献: Android custom listview display last item on first position
编辑
对于您在评论中提到的自动滚动大小写:
protected function configureListFields(ListMapper $listMapper)
{
/** @var Article article */
$article = $this->getSubject();
参考:Listview Scroll to the end of the list after updating the list