0

다음과 같이 동적 ViewPager를 생성합니다 : pls. 확인 : KeyboardPagerAdapter은 다음과 같습니다Dynamic ViewPager와 관련된 문제 -> 두 번째 레이아웃이 변경되지 않았습니다.

/** adding gridView created to main root layout.*/ 

    pager=new ViewPager(this); 
    pagerAdapter = new KeyboardPagerAdapter(); 

    pagerAdapter.addView (mGridImages, 0); 
    pagerAdapter.addView (mGridTextImages, 1); 

    pager.setAdapter (pagerAdapter); 
    ViewGroup.LayoutParams params = mGridImages.getLayoutParams(); 
    params.height = mDeviceHeight; 
    pager.setLayoutParams(params); 

    linRootLayout.addView(pager); 
    return linRootLayout; 

나의 등급 :

public class KeyboardPagerAdapter extends PagerAdapter{ 
// This holds all the currently displayable views, in order from left to right. 
private ArrayList<View> views = new ArrayList<View>(); 

//----------------------------------------------------------------------------- 
// Used by ViewPager. "Object" represents the page; tell the ViewPager where the 
// page should be displayed, from left-to-right. If the page no longer exists, 
// return POSITION_NONE. 
@Override 
public int getItemPosition (Object object) 
{ 
    int index = views.indexOf (object); 
    if (index == -1) 
     return POSITION_NONE; 
    else 
     return index; 
} 
// Used by ViewPager. Called when ViewPager needs a page to display; it is our job 
// to add the page to the container, which is normally the ViewPager itself. Since 
// all our pages are persistent, we simply retrieve it from our "views" ArrayList. 
@Override 
public Object instantiateItem (ViewGroup container, int position) 
{ 
    View v = views.get (position); 
    container.addView (v); 
    return v; 
} 


// Used by ViewPager. Called when ViewPager no longer needs a page to display; it 
// is our job to remove the page from the container, which is normally the 
// ViewPager itself. Since all our pages are persistent, we do nothing to the 
// contents of our "views" ArrayList. 
@Override 
public void destroyItem (ViewGroup container, int position, Object object) 
{ 
    container.removeView (views.get (position)); 
} 


// Used by ViewPager; can be used by app as well. 
// Returns the total number of pages that the ViewPage can display. This must 
// never be 0. 
@Override 
public int getCount() 
{ 
    return views.size(); 
} 


// Used by ViewPager. 
@Override 
public boolean isViewFromObject (View view, Object object) 
{ 
    return view == object; 
} 


// Add "view" to right end of "views". 
// Returns the position of the new view. 
// The app should call this to add pages; not used by ViewPager. 
public int addView (View v) 
{ 
    return addView (v, views.size()); 
} 

//----------------------------------------------------------------------------- 
// Add "view" at "position" to "views". 
// Returns position of new view. 
// The app should call this to add pages; not used by ViewPager. 
public int addView (View v, int position) 
{ 
    views.add (position, v); 
    return position; 
} 

//----------------------------------------------------------------------------- 
// Removes "view" from "views". 
// Retuns position of removed view. 
// The app should call this to remove pages; not used by ViewPager. 
public int removeView (ViewPager pager, View v) 
{ 
    return removeView (pager, views.indexOf (v)); 
} 

//----------------------------------------------------------------------------- 
// Removes the "view" at "position" from "views". 
// Retuns position of removed view. 
// The app should call this to remove pages; not used by ViewPager. 
public int removeView (ViewPager pager, int position) 
{ 
    // ViewPager doesn't have a delete method; the closest is to set the adapter 
    // again. When doing so, it deletes all its views. Then we can delete the view 
    // from from the adapter and finally set the adapter to the pager again. Note 
    // that we set the adapter to null before removing the view from "views" - that's 
    // because while ViewPager deletes all its views, it will call destroyItem which 
    // will in turn cause a null pointer ref. 
    pager.setAdapter (null); 
    views.remove (position); 
    pager.setAdapter (this); 

    return position; 
} 

//----------------------------------------------------------------------------- 
// Returns the "view" at "position". 
// The app should call this to retrieve a view; not used by ViewPager. 
public View getView (int position) 
{ 
    return views.get (position); 
} 
} 

내 문제는 내 응용 프로그램을 실행하면 첫 번째 페이지 내부 확인 표시됩니다 있다는 것입니다. 그러나 두 번째 호출기는 공백으로 표시됩니다 (흰색 페이지). 무엇이 문제 일 수 있습니까? PagerAdapter가 내가 한 것처럼 두 번째보기를 사용하지 않는 이유

pagerAdapter.addView (mGridImages, 0); pagerAdapter.addView (mGridTextImages, 1);

1> 두 번째보기를 추가하려면

Pls. 확인하고 안내 해줘. 감사합니다. .

답변

0

내 신비. 글로벌으로 두 번째 레이아웃의 가시성을 보이지 않게 설정했습니다.