我已经研究并尝试学习,但我不清楚并希望得到帮助。我玩过几种不同的策略,但尽管这确实是基本的东西,但无法弄清楚。
我有一个 FragmentPagerAdapter,它从字符串返回选项卡名称和内容文本。那些观点或片段——我太新了,我不清楚术语——是可滑动的,太棒了!(我遵循了许多教程和示例。)
现在我想添加一个 ListView 来滚动浏览在用户滑动时显示的大约 30 个固定内容文本。
我认为,这是迄今为止的相关代码:
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
Log.v(TAG, "getPageTitle");
String tabTitle = null;
switch(position) {
case 0:
tabTitle = "FAQs";
break;
case 1:
tabTitle = "Content";
break; return tabTitle;
}
/** This method will be invoked when a page is requested to create */
@Override
public Fragment getItem(int arg0) {
MyFragment myFragment = new MyFragment();
Bundle data = new Bundle();
data.putInt("current_page", arg0+1);
myFragment.setArguments(data);
return myFragment;
}
/** Returns the number of pages */
@Override
public int getCount() {
return PAGE_COUNT;
}
}
和 ViewPager:
public class Content extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contentpage);
/** Getting a reference to the ViewPager defined the layout file */
ViewPager pager = (ViewPager) findViewById(R.id.pager);
/** Getting fragment manager */
FragmentManager fm = getSupportFragmentManager();
/** Instantiating FragmentPagerAdapter */
MyFragmentPagerAdapter pagerAdapter = new MyFragmentPagerAdapter(fm);
/** Setting the pagerAdapter to the pager object */
pager.setAdapter(pagerAdapter);
}
}
和
public class MyFragment extends Fragment{
int mCurrentPage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Getting the arguments to the Bundle object */
Bundle data = getArguments();
/** Getting integer data of the key current_page from the bundle */
mCurrentPage = data.getInt("current_page", 0);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.myfragment_layout, container,false);
TextView tv = (TextView ) v.findViewById(R.id.tv);
tv.setMovementMethod(new ScrollingMovementMethod());
switch(mCurrentPage){
case 0:
tv.setText(" ");
break;
case 1:
tv.setText(R.string.faqs);
break;
case 2:
}
return tv;
}
我想要做的是创建一个 ListView,它是内容片段中返回的项目的快捷方式。ListView 应该显示 tabTitles,当它们被点击时,用户应该被带到可滑动的内容页面。
我在 ListView.java 中放了什么?
public class ListView {
}
提前感谢您提供的任何帮助。