在ViewPager上遇到一些问题, 我创建了一个带有以下instantiateItem方法的PagerAdapter
@Override
public Object instantiateItem(View collection, int position) {
View v = in.inflate(R.layout.weeklyoverviewview, null);
ListView lv = (ListView) v.findViewById(R.id.weeklyoverviewlist);
WeekAdapter a = new WeekAdapter(cxt, time.plusWeeks(position).getWeekOfWeekyear(), time.plusWeeks(position).getYear());
lv.setAdapter(a);
TopNavigatorView nv = (TopNavigatorView) v.findViewById(R.id.weeklyoverviewnavigator);
nv.setTitle("W" + time.plusWeeks(position).getWeekOfWeekyear() + " - " + time.plusWeeks(position).getYear());
((ViewPager) collection).addView(v, 0);
return v;
}
WeekAdapter看起来像
public class WeekAdapter extends BaseAdapter {
public ArrayList<View> views;
public WeekAdapter(Context context, int week, int year) {
LayoutInflater in = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
views = new ArrayList<View>();
DateTime d = new DateTime().withYear(year).withWeekOfWeekyear(week);
for (int i = 0; i < 7; i++) {
View v = in.inflate(R.layout.weeklyoverviewlisttitle, null);
TextView t = (TextView) v.findViewById(R.id.weeklytitletext);
t.setText(d.withDayOfWeek(i + 1).dayOfWeek().getAsText() + ", " + d.withDayOfWeek(i + 1).monthOfYear().getAsText() + " "
+ d.withDayOfWeek(i + 1).getDayOfMonth() + ", " + d.withDayOfWeek(i + 1).getYear());
views.add(v);
}
}
public int getCount() {
return views.size();
}
public Object getItem(int arg0) {
return views.get(arg0);
}
public long getItemId(int arg0) {
return views.get(arg0).getId();
}
public View getView(int arg0, View arg1, ViewGroup arg2) {
return views.get(arg0);
}
}
问题是前3页看到直接实例化似乎是正确的但是当我滑到另一个视图时我在listview中有7个项目但是文本是空的。 当我用text检查textview中的文本时,我看到文本设置正确但是没有出现。
编辑:像这样, http://i50.tinypic.com/108e8ac.png,不能表现为形象的声誉..
答案 0 :(得分:0)
我自己找到了解决方案,但不知道它为什么会起作用。 我将ListView的高度更改为fill_parent而不是wrap_content