.:: Jasa Membuat Aplikasi Website,Desktop,Android Order Now..!! | | Order Now..!! Jasa Membuat Project Arduino,Robotic,Print 3D ::.

ActionBar Tab Navigation in Android

0 komentar


بِسْــــــــــــــــمِ اﷲِالرَّحْمَنِ اارَّحِيم
bismillaahirrahmaanirrahiim

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
Assalamu'alaikum warahmatullahi wabarakatuh

Hi Guys!

In this tutorial we are learning about the ActionBar Tab Navigation means Swipe the Tab.
Swipe views provide lateral navigation between sibling screens such as tabs with a horizontal finger gesture (a pattern sometimes known as horizontal paging). This lesson teaches you how to create a tab layout with swipe views for switching between tabs.

For more details about the swipe the Tabs visit the android developer site Tab Swipe(Navigation).
I have implemented the tabs swipe by using the action bar and Fragment Page Adapter that is available in the android-support v4 library.
Implementation of PagerAdapter that represents each page as a Fragment that is persistently kept in the fragment manager as long as the user can return to the page.
For more details about the Fragment Page Adapter, please visit the android developer site Fragment Page Adapter.

With help of Fragment page Adapter we have implemented the Tabs Swipe(Navigation). Please watch the video for same.


So lets start the coding tabs swipe by using the action bar and fragment page adapter.

 

activity_main.xml






MainActivity.java

package com.sunil.actionbartabnavigation;

import com.sunil.actionabrtabnavigation.R;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.Menu;

public class MainActivity extends FragmentActivity {

ActionBar actionabar;
ViewPager viewpager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

actionabar = getActionBar();
actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

viewpager = (ViewPager) findViewById(R.id.pager);
FragmentManager fm = getSupportFragmentManager();

/** Defining a listener for pageChange */
ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener(){
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
actionabar.setSelectedNavigationItem(position);
}
};

/** Setting the pageChange listner to the viewPager */
viewpager.setOnPageChangeListener(pageChangeListener);

/** Creating an instance of FragmentPagerAdapter */
MyFragmentPagerAdapter fragmentPagerAdapter = new MyFragmentPagerAdapter(fm);

viewpager.setAdapter(fragmentPagerAdapter);
actionabar.setDisplayShowTitleEnabled(true);

/** Defining tab listener */
ActionBar.TabListener tabListener = new ActionBar.TabListener() {

@Override
public void onTabReselected(Tab arg0, android.app.FragmentTransaction arg1) {

}

@Override
public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) {
viewpager.setCurrentItem(tab.getPosition());

}

@Override
public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {

}
};

/** Creating Android Tab */
// Tab tab = actionabar.newTab().setText("My Friends").setIcon(R.drawable.myfriends).setTabListener(tabListener);
Tab tab = actionabar.newTab().setText("My Friends").setTabListener(tabListener);
actionabar.addTab(tab);
tab = actionabar.newTab().setText("Android Version").setTabListener(tabListener);
actionabar.addTab(tab);
tab = actionabar.newTab().setText("Android Phones").setTabListener(tabListener);
actionabar.addTab(tab);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

MyFriendsListFragment.java

package com.sunil.actionbartabnavigation;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class MyFriendsListFragment extends ListFragment{

/** An array of items to display in ArrayList */
String myfriends_list[] = new String[]{
"Abhi Tripathi",
"Sandeep Pal",
"Avi Diwakar",
"Shishir Verma",
"Amit Verma"
};


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

/** Creating array adapter to set data in listview */
ArrayAdapter adapter = new ArrayAdapter(getActivity().getBaseContext(), android.R.layout.simple_list_item_multiple_choice, myfriends_list);
setListAdapter(adapter);

return super.onCreateView(inflater, container, savedInstanceState);

}

@Override
public void onStart() {
super.onStart();
/** Setting the multiselect choice mode for the listview */
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

}
}

MyAndroidPhonesListFragment.java

package com.sunil.actionbartabnavigation;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MyAndroidPhonesListFragment extends ListFragment{

private String myandroidphone[]=new String[]{
"Samsung Android",
"Sony Experia",
"Micromax",
"Nokiya Lumia",
"Windows phone"
};

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){

ArrayAdapter adapter = new ArrayAdapter(getActivity().getBaseContext(), android.R.layout.simple_list_item_multiple_choice, myandroidphone);
setListAdapter(adapter);

return super.onCreateView(inflater, container, savedInstanceState);

}

@Override
public void onStart() {
super.onStart();
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

}
}

MyAndroidVersionListFragment.java

package com.sunil.actionbartabnavigation;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MyAndroidVersionListFragment extends ListFragment{

/** An array of items to display in ArrayList */
String android_versions[] = new String[]{
"Jelly Bean",
"IceCrean Sandwich",
"Honey Comb",
"Gingerbread",
"Froyo"
};

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){

ArrayAdapter adapter = new ArrayAdapter(getActivity().getBaseContext(), android.R.layout.simple_list_item_multiple_choice, android_versions);
setListAdapter(adapter);

return super.onCreateView(inflater, container, savedInstanceState);

}

@Override
public void onStart() {
super.onStart();
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

}
}

MyFragmentPagerAdapter.java

package com.sunil.actionbartabnavigation;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class MyFragmentPagerAdapter extends FragmentPagerAdapter{

final int PAGE_COUNT = 3;

public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);

}

/** This method will be invoked when a page is requested to create */
@Override
public Fragment getItem(int arg0) {
Bundle data = new Bundle();
switch(arg0){

/** Android tab is selected */
case 0:
MyFriendsListFragment myfriends = new MyFriendsListFragment();
data.putInt("current_page", arg0+1);
myfriends.setArguments(data);
return myfriends;

case 1:
MyAndroidVersionListFragment androidversion = new MyAndroidVersionListFragment();
data.putInt("current_page", arg0+1);
androidversion.setArguments(data);
return androidversion;

case 2:
MyAndroidPhonesListFragment androidphone = new MyAndroidPhonesListFragment();
data.putInt("current_page", arg0+1);
androidphone.setArguments(data);
return androidphone;
}

return null;
}

/** Returns the number of pages */
@Override
public int getCount() {
return PAGE_COUNT;
}

}






You can download the source code Action Bar Tab Navigation

Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
NB :: Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code, membeli hardware elektronika untuk kepentingan Perusahaan maupun Tugas Akhir (TA/SKRIPSI), Insyaallah Saya siap membantu, untuk Respon Cepat dapat menghubungi kami, melalui :

No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com


atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :

ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِين
Alhamdulilah hirobil alamin

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ
wassalamualaikum warahmatullahi wabarakatuh


Artikel ActionBar Tab Navigation in Android, Diterbitkan oleh scodeaplikasi pada Minggu, 11 Agustus 2013. Semoga artikel ini dapat menambah wawasan Anda. Website ini dipost dari beberapa sumber, bisa cek disini sumber, Sobat diperbolehkan mengcopy paste / menyebar luaskan artikel ini, karena segala yang dipost di public adalah milik public. Bila Sobat tertarik Ingin membuat software, membeli software, membeli source code ,Dengan Cara menghubungi saya Ke Email: Fajarudinsidik@gmail.com, atau No Hp/WA : (fajar) : 085369237896, (puat) : 085267792168.

Tawk.to