本文介绍了Android Wear:具有FragmentPagerAdapter的WearableActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用WearableActivity时,您无法达到FragmentPagerAdapter
所需的getSupportFragmentManager()
,因此您需要使用getFragmentManager()
.
When using the WearableActivity you can't reach getSupportFragmentManager()
which FragmentPagerAdapter
requires, so you need to use getFragmentManager()
.
public MyWearActivity extends WearableActivity {
public ArrayList<Fragment> mFragments;
public ArrayList<String> mTitles;
public ViewPager mViewPager;
public PageFragmentPagerAdapter mPagerAdapter;
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.main);
fragments = new ArrayList<>();
mTitles = new ArrayList<>();
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mPagerAdapter = new PageFragmentPagerAdapter(getFragmentManager()); <-- PROBLEM
// More code
}
}
寻呼机适配器
public class PageFragmentPagerAdapter extends FragmentPagerAdapter {
public PageFragmentPagerAdapter(FragmentManager fm) {
super(fm); <-- PROBLEM
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public PageFragment getItem(int position) {
return mFragments.get(position);
}
@Override
public CharSequence getPageTitle(int position) {
return mTitles.get(position);
}
}
在WearableActivity
中使用FragmentPagerAdapter
怎么办?
推荐答案
遇到了同样的问题.
我已经添加了它
compile 'com.android.support:support-v13:23.1+'
到build.gradle文件中的依赖项.然后在其中使用FragmentPagerAdapter添加
to the dependencies in the build.gradle file. Then where you use the FragmentPagerAdapter add
import android.support.v13.app.FragmentPagerAdapter;
不确定是否还有更好的方法.
Not sure if there's a better way yet.
这篇关于Android Wear:具有FragmentPagerAdapter的WearableActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!