我有一个从适配器填充的列表视图。我的原始代码数据是从表中返回的,但现在我需要从联合查询中获取代码,因此我使用的示例将不再起作用,并且我无法找到如何使用查询为了这。我正在使用一个ORMrepository。 在我ORMrepository我有这个功能在适配器中使用查询列表视图
public IList<Coe> GetmyCoe()
{
using (var database = new SQLiteConnection(_helper.WritableDatabase.Path))
{
string query = "SELECT Coe.Id, Adult.LName + ', ' + Adult.MName AS Name, Coe.Createdt FROM Adult INNER JOIN Coe ON Adult.CoeMID = Coe.Id";
return database.Query<Coe>(query);
}
}
实际上返回我想要的数据。 然后在我的活动页面我有这个。
_list = FindViewById<ListView>(Resource.Id.List);
FindViewById<ListView>(Resource.Id.List).ItemClick += new System.EventHandler<ItemEventArgs>(CoeList_ItemClick);
var Coe = ((OmsisMobileApplication)Application).OmsisRepository.GetmyCoe();
_list.Adapter = new CoeListAdapter(this, Coe);
我的适配器页面是我遇到问题的地方,我知道它设置为查看我不再做的表格。但我现在不知道如何改变它。当前CoeListAdapter是:
public class CoeListAdapter : BaseAdapter
{
private IEnumerable<Coe> _Coe;
private Activity _context;
public CoeListAdapter(Activity context, IEnumerable<Coe> Coe)
{
_context = context;
_Coe = Coe;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var view = (convertView
?? _context.LayoutInflater.Inflate(
Resource.Layout.CoeListItem, parent, false)
) as LinearLayout;
var Coe = _Coe.ElementAt(position);
view.FindViewById<TextView>(Resource.Id.CoeMID).Text = Coe.Id.ToString();
//view.FindViewById<TextView>(Resource.Id.GrdnMaleName).Text = Coe.Name;
view.FindViewById<TextView>(Resource.Id.CreateDt).Text = Coe.CreateDt;
return view;
}
public override int Count
{
get { return _Coe.Count(); }
}
public Coe GetCoe(int position)
{
return _Coe.ElementAt(position);
}
public override Java.Lang.Object GetItem(int position)
{
return null;
}
public override long GetItemId(int position)
{
return position;
}
}
如何建立CoeListAdapter.cs页面,以便它可以使用在数据传递。正如你所看到的,我有一个注释掉了我填充TextView的行,因为Coe.Name不在Coe的表模型中。但它在查询中返回。我相信我的问题是IEnumerable,但我该怎么改变它。我是新手机发展和起诉VS2010单声道