Android – listview. Setfooterview (V) footer changes are not visible in the listview displayed by viewpager

I called

listView.setFooterView(v)

Now I should add that listview is located in a view (not a frame) added to viewpager

Therefore, the view containing listview is located in the view pager. If I switch back and forth between views, I will see the changes, but not. So far, I have tried to invalidate most of the content, including the entire viewpager, but it still does not display

Internal activity layout:

 <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"
/>

Then I have three pages, each of which looks like this:

 <?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>

So I have the above ideas and immediately create them in oncreate () of the main activity

 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) {


    }


}

I'll update a few lines

     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();
}

So I want the effect of changing addfooterview to be visible immediately

resolvent:

The solution is to add the footer view first and then set the adapter. If you set the adapter first and then add the footer view, it will now be displayed. However, you can use removefooterview (V) without resetting the adapter

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>