我想在我的ListView
中以其他颜色制作行 - Xamarin.Android
C#项目。
这是我的代码
ListView DialogoList = (ListView)FindViewById(Resource.Id.DialogoList);
Data data = new Data();
string[] dialogolist = data.Dialogo(Data.level, Data.Lesson);
DialogoList.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, dialogolist);
答案 0 :(得分:1)
正如@Nongthonbam Tonthoi所说,你可以根据位置覆盖GetView
颜色:
例如:
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.CustomView, null);
view.FindViewById<TextView>(Resource.Id.Text1).Text = item.Heading;
view.FindViewById<TextView>(Resource.Id.Text2).Text = item.SubHeading;
view.FindViewById<ImageView>(Resource.Id.Image).SetImageResource(item.ImageResourceId);
if (position % 2 == 0)
{
view.FindViewById<RelativeLayout>(Resource.Id.listView_item_bg).SetBackgroundColor(Color.Pink);
}
else
{
view.FindViewById<RelativeLayout>(Resource.Id.listView_item_bg).SetBackgroundColor(Color.Blue);
}
return view;
}
有关完整代码,您可以参考此sample。