问题描述
我是pretty的多是新手,当涉及到编码的android,我不知道你怎么能有刷卡美景的动作条。
I'm pretty much a newbie when it comes to coding in android and I wonder how you can make a actionbar with swipe views.
我的code: http://pastebin.com/iHZn27H3
错误
Unknown entity 'ViewPager' on line 11
Unknown entity 'ViewPager' on line 21
Unknown type of field 'mViewPager' on line 21
Unknown type of field 'mViewPager' on line 22
Unknown method on line 22
Unknown entity 'ViewPager' on line 23
Unknown type of field 'mViewPager' on line 34
Unknown mrthod on line 34
我如何修复这些错误?
How do I fix those errors?
编辑:错误,现在走了,但我不能切换标签我刷卡,只有通过点击。 code: http://pastebin.com/iHZn27H3
Errors now gone but I can't switch tab my swiping, only by clicking. Code: http://pastebin.com/iHZn27H3
推荐答案
- 答案到第一子问题:
我不知道哪一个IDE你正在使用,但在的IntelliJ你必须去模块设置>库>点击加号>的Java>库(文件夹)> Android的支持,v4.jar。在Eclipse中,很可能,你必须去构建路径>配置构建路径>Java构建路径>添加JAR文件>库> Android的支持 - v4.jar
I do not know which IDE you are using, but in Intellij you have to go to 'Module Settings' > 'Libraries' > click on plus sign > Java > libs (folder) > android-support-v4.jar. In Eclipse, probably, you have to go to 'Build Path' > 'Config Build Path' > 'Java Build Path' > 'Add JARs' > 'libs' > android-support-v4.jar
- 答案到第二子问题:
扩展的作为一个例子:
Tab1Fragment.java:
public class Tab1Fragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.live, container,false);
TextView tv = (TextView) view.findViewById(R.id.status);
tv.setText("Fragment1");
return view;
}
}
Tab2Fragment.java:
public class Fragment2 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.live, container,false);
TextView tv = (TextView) view.findViewById(R.id.status);
tv.setText("Fragment2");
return view;
}
}
live.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/status"/>
</LinearLayout>
主要活动(ViewPagerFragmentActivity.java):
public class ViewPagerFragmentActivity extends FragmentActivity {
private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main);
//initialsie the pager
this.initialisePaging();
}
private void initialisePaging() {
List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this, Fragment1.class.getName()));
fragments.add(Fragment.instantiate(this, Fragment2.class.getName()));
this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager)super.findViewById(R.id.viewpager);
pager.setAdapter(this.mPagerAdapter);
}
}
main_activity.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+android:id/viewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></android.support.v4.view.ViewPager>
</LinearLayout>
PagerAdapter.java:
public class PagerAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public PagerAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
@Override
public int getCount() {
return this.fragments.size();
}
}
这篇关于请用刷卡美景的动作条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!