我正在使用一个有 5 页的片段寻呼机适配器。我将适配器设置为查看寻呼机,如下所示
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;
我将适配器设置如下
m_oPager.setAdapter(m_oPagerAdapter);
我的问题是如何动态添加和删除第 5 页...比如在某些情况下我需要第 5 页,而在某些情况下我需要删除第 5 页。