# 单词本页面
页面的特色是可以滑动触摸切换页面,每个页面显示不同的单词,这个功能是如何实现的呢?
答案是ViewPager+Fragment
关于这个知识点,可以直接查看这篇文章:[fragment+viewpager实践](http://blog.csdn.net/bobo8945510/article/details/52821741)
你一定会有收获的。
单词模块的核心也在这里:
# WordsPageActivity 是单词本模块
~~~
public class WordsPageActivity extends FragmentActivity {
JellyViewPager pager;
int currentItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_words_page);
NoteDao noteDao=((DemoApplication)getApplication()).getDaoSession().getNoteDao();
List<Note> list=noteDao.queryBuilder().list();
if(list.size()<=0){
Toast.makeText(getApplicationContext(),"单词本空无一物!",Toast.LENGTH_LONG).show();
Note note=new Note();
note.setSrcWords("无");
note.setText("无");
list.add(note);
}
pager = (JellyViewPager) findViewById(R.id.myViewPager1);
//pager.setAdapter(new TestPagerAdapter(this));
pager.setAdapter(new TestFragPagerAdapter((getSupportFragmentManager()),list));
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int state) {
switch(state){
case 1: //正在滑动
break;
case 2: //滑动结束
break;
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageSelected(int arg0) {
}
});
}
public void onClick(View view) {
switch(view.getId()){
case R.id.preBtn:
pager.showPre();
break;
case R.id.nextBtn:
pager.showNext();
break;
}
}
}
~~~