6
我正在使用5頁的片段尋呼機適配器。和IM設置適配器,以查看尋呼機如下刪除並添加頁面到FragmentPagerAdapter
public class xxx extends FragmentPagerAdapter
{
final int PAGE_COUNT_LOGGED_IN = 6;
final int PAGE_COUNT_LOGGED_OUT = 2;
TextView oTextView = null;
LayoutInflater inflater = null;
PagerTabStrip m_oPageTabStrip = null;
String m_strTab = null;
String[] m_strArray = null;
Context m_oContext = null;
/** Constructor of the class */
public xxxx (Context context, android.support.v4.app.FragmentManager oFragmentManager)
{
super (oFragmentManager);
m_oContext = context;
}
/** This method will be invoked when a page is requested to create */
@Override
public Fragment getItem(int arg0)
{
xxxxFragment myFragment = new xxxFragment();
Bundle data = new Bundle();
data.putInt("current_page", arg0+1);
myFragment.setArguments(data);
return myFragment;
}
/** Returns the number of pages */
@Override
public int getCount()
{
if (Utility.m_bIsLoggedIn == true)
{
return PAGE_COUNT_LOGGED_IN;
}
else
{
return PAGE_COUNT_LOGGED_OUT;
}
}
@Override
public CharSequence getPageTitle(int position)
{
String strText = " ";
switch(position)
{
case 0:
strText = getBaseContext().getString(R.string.ccc);
break;
case 1:
strText = getBaseContext().getString(R.string.bbb);
break;
case 2:
strText = getBaseContext().getString(R.string.bbb);
break;
case 3:
strText = getBaseContext().getString(R.string.bbb);
break;
case 4:
strText = getBaseContext().getString(R.string.bbb);
break;
case 5:
strText = getBaseContext().getString(R.string.Sbbb);
break;
}
}
和在片段我單獨創建一個線性佈局對於每一頁,如下
bbb.m_oSharedPage = (LinearLayout) LayoutInflater.from(Utility.m_oService).inflate(R.layout.viewpage, null);
iView = Utility._YOURS_SHARED;
oCurrentPage = .m_oSharedPage;
和IM設置適配器如下
m_oPager.setAdapter(m_oPagerAdapter);
我的問題是我如何添加和刪除第5頁動態...像某些情況下,我需要第5頁和一些情況下,我需要刪除第5頁。
喜...感謝您的答案...但我已經試過it..the問題..when數發生變化,notfy適配器被稱爲頁面沒有顯示,但當我滾動當前最後一頁時顯示頁面的內容...因爲adpater在開始時創建了最後一頁 – user1340801 2013-04-08 07:13:07
奇怪的是,我沒有得到同樣的反應,我不能滾動到我已刪除的頁面。 – jnthnjns 2013-04-08 12:27:40
不,你不能滾動,但當你拉長滾動,你可以看到該頁面的內容...你不會看到標題和所有,但只是內容 – user1340801 2013-04-09 11:41:51