我试图在viewflipper中显示列表视图。但是从不调用GetView()方法。我不确定这是否与它有关,但我有一个以上的适配器。但是第一个确实有效。这是我的适配器代码:
using System.Collections.Generic;
using Android;
using Android.App;
using Android.Graphics;
using Android.Views;
using Android.Widget;
using CardAppReal.Lib.Models;
namespace CardAppReal.Assets
{
public class SetAdapter : BaseAdapter<Set>
{
List<Set> items;
Activity context;
public SetAdapter(Activity context, List<Set> items)
: base()
{
this.context = context;
this.items = items;
}
public override long GetItemId(int position)
{
return position;
}
public override Set 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(NavigationDrawerTest.Resource.Layout.rowlayout, null);
view.FindViewById<TextView>(NavigationDrawerTest.Resource.Id.Text1).Text = item.Name;
view.FindViewById<TextView>(NavigationDrawerTest.Resource.Id.Text2).Text = item.CardAmount + " Cards";
view.SetBackgroundColor(Color.Argb(150, 153, 217, 234));
return view;
}
}
}
这是我创建我的东西的方法:
private void OnSerieListItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
vf = FindViewById<ViewFlipper>(Resource.Id.viewflipper);
var listView = sender as ListView;
var t = Series[e.Position];
Android.Widget.Toast.MakeText(this, t.Series, Android.Widget.ToastLength.Short).Show();
LoadSets(t.Series);
vf.DisplayedChild = 2;
}
private async Task LoadSets(string serie)
{
SetDataService setDataService = new SetDataService(new SetRepo());
Sets = await setDataService.GetSetAsync(serie);
var listViewSets = FindViewById<ListView>(Resource.Id.ListViewSets);
//drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
listViewSets.Adapter = new SetAdapter(this, Sets);
listViewSets.ItemClick += OnSetListItemClick;
}
适配器中的items.count永远不会为0所以我不确定它为什么不被调用。
编辑:
当我调试它时,我注意到它连续几次跳过count方法。不确定这是否与它有关。但它永远不会显示0,所以它应该进行getview。
EDIT2:
这是我的listview的axml。布局axml应该工作得很好,因为我在我的第一个适配器中使用相同的那个,它在那里工作。
<?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">
<TextView
android:text="Test Sets"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ListViewSets" />
</LinearLayout>