我打电话
listView.setFooterView(v)
但看不到任何变化。现在我应该补充一点,listView 位于添加到 ViewPager 中的视图(不是框架)内。
因此,包含 listView 的 View 位于视图寻呼机内。如果我在视图之间来回切换,那么我会看到变化,但不会。到目前为止,我已经尝试使包括整个 ViewPager 在内的大多数内容无效,但它仍然没有显示。
我有内部活动布局:
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_weight="1"
/>
然后我有三个页面,每个页面如下所示:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listListDisplayer1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listMyList1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:fastScrollEnabled="true" />
<include layout="@layout/advertisement" />
</FrameLayout>
所以我有上面的视图,并立即在主要活动的 onCreate() 中创建它们。
MyPageAdapter extends ViewPagerAdapter{
int getCount() {
return 3;
}
public Object instantiateItem(View collection, int position) {
View view=null;
switch (position) {
case 0:
view = getMyView1();
break;
case 1:
view = getMyView2();
break;
case 2:
view = getMyView2();
break;
}
if ((view != null) && ((ViewPager) collection).findViewById(view.getId()) == null)
{
((ViewPager) collection).addView(view, 0);
}
return view;
}
private View getMyView1()
{
return mMyView1;
}
private View getMyView2()
{
return mMyView2;
}
private View getMyView3()
{
return mMyView3;
}
@Override
public void destroyItem(View view, int arg1, Object arg2) {
((ViewPager) view).removeView((View) arg2);
}
@Override
public void finishUpdate(View view) {
}
@Override
public boolean isViewFromObject(View view, Object arg1) {
return view == ((View) arg1);
}
@Override
public void restoreState(Parcelable parcel, ClassLoader classLoader) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View view) {
}
}
我将更新几行......
private class PageChangeListener implements OnPageChangeListener {
@Override
public void onPageScrollStateChanged(int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int pageNum) {
Logout.debug("pageSelected :"+pageNum);
if (pageNum == 0)
{
prepareMyView1();
}
else if (pageNum == 2)
{
prepareMyView2();
}
else if (pageNum == 3)
{
prepareMyView3();
}
}
}
private void prepareMyView1() // each is like this setting adapter on ListView
{
setMyList1Adapter();
}
private void prepareMyView2() // each is like this setting adapter on ListView
{
setMyList2Adapter();
}
所以我希望改变 addFooterView 的影响 | 立即可见。