Skip to content Skip to sidebar Skip to footer

Make A Actionbar With Swipe Views?

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. My code: http://pastebin.com/iHZn27H3 Errors Unknown entity

Solution 1:

  • Answer to the first sub-question:

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


  • Answer to the second sub-question:

Extending http://thepseudocoder.wordpress.com/2011/10/05/android-page-swiping-using-viewpager/ as an example:

Tab1Fragment.java:

publicclassTab1FragmentextendsFragment {

    @Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Viewview= inflater.inflate(R.layout.live, container,false);
        TextViewtv= (TextView) view.findViewById(R.id.status);
        tv.setText("Fragment1");

        return view;
    }
}

Tab2Fragment.java:

publicclassFragment2extendsFragment {

    @Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Viewview= inflater.inflate(R.layout.live, container,false);
        TextViewtv= (TextView) view.findViewById(R.id.status);
        tv.setText("Fragment2");

        return view;
    }
}

live.xml:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:layout_height="fill_parent"android:layout_width="fill_parent"android:id="@+id/status"/></LinearLayout>

main activity (ViewPagerFragmentActivity.java):

publicclassViewPagerFragmentActivityextendsFragmentActivity {
    private PagerAdapter mPagerAdapter;
    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       super.setContentView(R.layout.activity_main);
       //initialsie the pagerthis.initialisePaging();
    }

    privatevoidinitialisePaging() {
        List<Fragment> fragments = newVector<Fragment>();
        fragments.add(Fragment.instantiate(this, Fragment1.class.getName()));
        fragments.add(Fragment.instantiate(this, Fragment2.class.getName()));
        this.mPagerAdapter  = newPagerAdapter(super.getSupportFragmentManager(), fragments);
        ViewPagerpager= (ViewPager)super.findViewById(R.id.viewpager);
        pager.setAdapter(this.mPagerAdapter);
    }
}

main_activity.xml:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><android.support.v4.view.ViewPagerandroid:id="@+android:id/viewpager"android:layout_width="fill_parent"android:layout_height="fill_parent"></android.support.v4.view.ViewPager></LinearLayout>

PagerAdapter.java:

publicclassPagerAdapterextendsFragmentPagerAdapter {
private List<Fragment> fragments;

publicPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
    super(fm);
    this.fragments = fragments;
}

@Overridepublic Fragment getItem(int position) {
    returnthis.fragments.get(position);
}

@OverridepublicintgetCount() {
    returnthis.fragments.size();
}
}

Post a Comment for "Make A Actionbar With Swipe Views?"