Check any fragment is presented in Layout in android? - android

In my application.there are five button . when curresponding button is pressed the fragment will load in the linear layout.what i want is if any button is pressed the current fragment in the layout should dettach and fragment corresponding to button should placed.i need a common method to remove previously placed fragment.i know we can remove the fragment specifically using its id.i dont need that.i want a common method to remove the fragments.here is my java class.
Button b1, b2, b3, b4, b5;
// Declare Variables
ActionBar mActionBar;
ViewPager mPager;
FragmentManager fm;
setContentView(R.layout.activity_main);
fm = getSupportFragmentManager();b1 = (Button) findViewById(R.id.fbbutton1);
b2 = (Button) findViewById(R.id.fbbutton2);
b3 = (Button) findViewById(R.id.fbbutton3);
b4 = (Button) findViewById(R.id.fbbutton4);
b5 = (Button) findViewById(R.id.fbbutton5);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
FragmentTab1 f1 = new FragmentTab1();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragmentgroup, f1, "A");
ft.commit();
}
});
b2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (getSupportFragmentManager().findFragmentById(R.id.detail_screen) != null) {
getSupportFragmentManager().popBackStack();
} //to do add fragment
FragmentTab2 f2 = new FragmentTab2();
FragmentTransaction ft = fm.beginTransaction();
// fm.popBackStack(fm.getBackStackEntryCount(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
// - Use FragmentManager.getBackStackEntryCount()/getBackStackEntryAt().getId() to retrieve the ID of the first entry on the back stack, and FragmentManager.popBackStack(int id, FragmentManager.POP_BACK_STACK_INCLUSIVE).
// ft.replace(R.id.fragmentgroup, f2);
ft.add(R.id.fragmentgroup, f2, "B");
ft.commit();
}
});
b3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
FragmentTab3 f3 = new FragmentTab3();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragmentgroup, f3, "C");
ft.commit();
}
});
b4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
FragmentTab4 f4 = new FragmentTab4();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragmentgroup, f4, "D");
ft.commit();
}
});
b5.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
FragmentTab5 f5 = new FragmentTab5();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragmentgroup, f5, "E");
ft.commit();
}
});
the layout for showing the fragments in my xml
<LinearLayout
android:id="#+id/fragmentgroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#F2A4A9"
android:orientation="horizontal" >

You need a common method to replace fragments corresponding to your button click.
So, you can use replace method in FragmentTransaction to do the job in common method.
Code will be,
public void replaceAFragment(int frag_container, Fragment aFragment, String tag) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(frag_container, aFragment, tag);
transaction.commit();
}
Whenever you want to load a fragment, you no need to remove but simply replace it with your new fragment,
b3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
FragmentTab3 f3 = new FragmentTab3();
replaceAFragment(R.id.fragmentgroup,f3,"FRAGMENT THREE");
}
});
b4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
FragmentTab4 f4 = new FragmentTab4();
replaceAFragment(R.id.fragmentgroup,f4,"FRAGMENT FOUR");
}
});
b5.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
FragmentTab5 f5 = new FragmentTab5();
replaceAFragment(R.id.fragmentgroup,f5,"FRAGMENT FIVE");
}
});
Now you have a common method to place fragments. You may also do, detach and remove inside with the tag.

Related

Fragment not launched from another fragment

I have a fragment with two buttons: btnEdit and btnExamen.
Each button has an OnClickListener.
Here is the code:
btnEdit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mPref = getActivity().getSharedPreferences(MISDATOS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = mPref.edit();
editor.putString("id_empleo","No");
editor.putString("id_grado","No");
editor.apply();
HomeFragment firstFragment = new HomeFragment();
((MainActivity)getActivity()).getSupportFragmentManager().beginTransaction()
.replace(R.id.frame, firstFragment).commit();
}
});
btnExamen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "Iniciando examen", Toast.LENGTH_SHORT).show();
ExamenesFragment secondFragment = new ExamenesFragment();
((MainActivity)getActivity()).getSupportFragmentManager().beginTransaction()
.replace(R.id.frame, secondFragment).commit();
}
});
The issue is that the first method works fine, HomeFragment is launched.
But the second method is not launching fragment ExamFragment. The toast is launched.
I am not able to see any difference at the code that could be the problem.
Replace the current Fragment with the new Fragment and push transaction onto the backstack. This preserves back button behaviour...
Creating a new Activity really defeats the whole purpose to use fragments anyway...very counter productive.
btnEdit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
...
// Create new fragment and transaction
HomeFragment firstFragment = new HomeFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the frame view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.frame, firstFragment );
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
});
btnExamen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
...
ExamenesFragment secondFragment= new ExamenesFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.frame, secondFragment);
transaction.addToBackStack(null);
transaction.commit();
}
});

Fragment keeps on adding when the button is clicked

ImageButton imageButton3 =(ImageButton)view.findViewById(R.id.item_two_timer_id);
imageButton3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getFragmentManager().beginTransaction()
.replace(R.id.container2_main , new TimerFragment2())
.addToBackStack(null)
.commit();
While adding fragment add a tag to identify it.get the fragment by tag and see if the fragment is present.If it is not present create a new Instance and add it.
ImageButton imageButton3 = (ImageButton) view.findViewById(R.id.item_two_timer_id);
imageButton3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TimerFragment2 timerFragment2;
timerFragment2 = (TimerFragment2) getFragmentManager().findFragmentByTag(TimerFragment2.class.getSimpleName());
if(timerFragment2==null){
timerFragment2=new TimerFragment2();
getFragmentManager().beginTransaction()
.replace(R.id.container2_main, timerFragment2,TimerFragment2.class.getSimpleName())
.addToBackStack(TimerFragment2.class.getSimpleName())
.commit();
}else {
//Dont create fragment again
}
}
});
please try this code if you are setting one fragment
private void initFragment() {
SelectTypeFragment fragment = new SelectTypeFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right); //if you want to set animation
fragmentTransaction.replace(R.id.fl_addvehicle, fragment);
fragmentTransaction.commit();
}
if you are replacing one fragment to with another.
void goToNextFragment() {
((CreateOfferActivity) this.getActivity()).setCreateOfferModel(createOfferModel);
SelectVehicleFragment fragment = new SelectVehicleFragment();
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
fragmentTransaction.replace(R.id.fl_create_offer, fragment).
addToBackStack("select_vehicle");
fragmentTransaction.commit();
}
You can check it in Fragment but first,
You need to create an object of Fragment TimerFragment2 and check if it's visible or not in timerFragment.isVisible()
ImageButton imageButton3 =(ImageButton)view.findViewById(R.id.item_two_timer_id);
TimerFragment2 timerFragment = new TimerFragment2();
imageButton3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!timerFragment.isVisible())
getFragmentManager().beginTransaction()
.replace(R.id.container2_main , timerFragment)
.addToBackStack(null)
.commit();

Call Fragment from activity

I have a Navigation drawer activity and it contains couple of Fragments. My problem is I want to call the Navigation drawer activity class in button click which should have fragment B, by default navigation drawer has fragment A.
I am posting my code here:
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(getApplicationContext(),Navigation.class));
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.content_frame, new FragmentB());
tx.commit();
finish();
}
});
Where content_frame is the area were I want to replace fragment B view..
try this approach
in your button click send extra data to check what fragment you need
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), Navigation.class);
intent.putExtra("SELECTEDVALUE", 2);//1 for fragament A use 2 for fragment B
startActivity(intent);
}
});
Now, in your oncreate() method of Navigation Activity
Bundle extras = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
int selectedValue = extras.getInt("SELECTEDVALUE");
switch (selectedValue) {
case 1:
goToFragment(new A(), false);
break;
case 2:
goToFragment(new B(), false);
break;
finally gotoFragment is...
private void goToFragment(Fragment fragment, boolean addToBackStack) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if (addToBackStack) {
transaction.addToBackStack(null);
}
transaction.replace(R.id.container, fragment).commit();
}
Try below code;
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Fragment fragment = new FragmentB();
FragmentManager fm =getActivity().getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.commit();
}
});
Just make an instance of FragmentB like this
FragmentB fragment - new FragmentB();
and then pass it like this .
tx.replace(R.id.content_frame, fragment);
tx.commit();
now you can access all the variables and methods of fragment from your activity using instance fragment. like this fragment.methodName();
Try this code:
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(R.id.content_frame, new FragmentB(), "fragmentB").addToBackStack(null).commit();
}
});
hope it'll solve your problem.

Why my new fragment can't subscribe otto

I have made a post in my activity, and it works well in the first fragment BlankFragment, however, when I tried to replace BlankFragment with BlackFragment2, and do the same subscribe, it can't subscribe anymore, here is the code.
MainActivity:
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().add(R.id.fr1, new BlankFragment()).commit();
button = (Button)findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BusStation.getBus().post(new Message("hellworld"));
}
});
btn2 = (Button)findViewById(R.id.btn2);
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FragmentManager fragmentManager1 = getSupportFragmentManager();
fragmentManager1.beginTransaction().replace(R.id.fr1, new BlankFragment2()).commit();
BusStation.getBus().post(new Message("zhengzhi zhou"));
}
});
}
BlankFragment and BlankFragment2 are using the same code:
#Override
public void onResume() {
super.onResume();BusStation.getBus().register(this);
}
#Override
public void onPause() {
super.onPause();
BusStation.getBus().unregister(this);
}
#Subscribe
public void receiveMsg(Message msg){
textView.setText(msg.getMsg());
}
Can anyone help me with this?
Use commitNow() instead Of commit()
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
// Replace the contents of the container with the new fragment
ft.replace(R.id.fragment_place, fragment);
// or ft.add(R.id.your_placeholder, new FooFragment());
// Complete the changes added above
ft.commitNow();

how to add imagebuttons on horizontal scroll view of tabs so as to scroll on left and right by those image buttons in android studio?

Please help
Can anyone help me out plz
public class FragmentForScrollBar extends Fragment {
private HorizontalScrollView hsv;
Button left, right;
int currentScrollX = 0;
Toolbar Toolbar;
RelativeLayout RelativeLayout;
ImageButtonhome,player,download,playlist,stream,wish,hit,instrument,news,extras;
TextView t;
FragmentTransaction fragmentTransaction;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragmentforscrollbar,null);
MyPlayer playerFragment = new MyPlayer();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, playerFragment, null);
fragmentTransaction.commit();
hsv = (HorizontalScrollView) view.findViewById(R.id.horizontalScrollView);
t = (TextView)view.findViewById(R.id.toolbartitle);
home =(ImageButton)view.findViewById(R.id.imageButtonhomea);
player =(ImageButton)view.findViewById(R.id.imageButtonaa);
playlist =(ImageButton)view.findViewById(R.id.imageButtonca);
download =(ImageButton)view.findViewById(R.id.imageButtonba);
stream =(ImageButton)view.findViewById(R.id.imageButtonda);
wish =(ImageButton)view.findViewById(R.id.imageButtonea);
hit =(ImageButton)view.findViewById(R.id.imageButtonfa);
instrument =(ImageButton)view.findViewById(R.id.imageButtonga);
news =(ImageButton)view.findViewById(R.id.imageButtonha);
extras =(ImageButton)view.findViewById(R.id.imageButtonia);
home.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Home");
Fragment Home = new Home();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, Home);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
player.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Player");
Fragment Myplayer = new MyPlayer();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, Myplayer);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
playlist.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment yourPlayList = new Your_Playlist();
fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.containerView, yourPlayList);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
download.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("MyDownload");
Fragment myDownload = new Downloads();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,myDownload);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
stream.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Streaming");
Fragment uzBek1 = new UzBek();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,uzBek1);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
wish.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Your Wishes");
Fragment sendWishes = new wishes();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,sendWishes);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
hit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Hit Parade");
Fragment hitParade = new hits();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,hitParade);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
instrument.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Uzbek Instruments");
Fragment uzBek1 = new UzBek();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,uzBek1);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
news.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("News");
Fragment news = new news();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,news);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
extras.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Extras");
Fragment extras = new extras();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, extras);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
return view;
}
}
sorry code was too long so i captured the image of the xml module file
Please see the above code and let me know the solution for scrolling the mini scroll layout on left and right by image buttons.
I am using two arrow buttons and tell me this also that what to do if i want to hide them in between the scrolling. Now can someone help me out please
For anyone who might be puzzled up with the same issue:
public class FragmentForScrollBar extends Fragment {
SeekBar verticalSeekBar=null;
private HorizontalScrollView hsv, hsv2;
Toolbar Toolbar;
ImageButton home,player,download,playlist,stream,wish,hit,instrument,news,extras, bP,bN;
ImageButton homea,playera,downloada,playlista,streama,hita,wisha,instrumenta,newsa, extrasa;
TextView t;
FragmentTransaction fragmentTransaction;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragmentforscrollbar,null);
MyPlayer playerFragment = new MyPlayer();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, playerFragment, null);
fragmentTransaction.commit();
hsv = (HorizontalScrollView) view.findViewById(R.id.horizontalScrollView);
t = (TextView)view.findViewById(R.id.toolbartitle);
home =(ImageButton)view.findViewById(R.id.imageButtonhomea);
player =(ImageButton)view.findViewById(R.id.imageButtonaa);
playlist =(ImageButton)view.findViewById(R.id.imageButtonca);
download =(ImageButton)view.findViewById(R.id.imageButtonba);
stream =(ImageButton)view.findViewById(R.id.imageButtonda);
wish =(ImageButton)view.findViewById(R.id.imageButtonea);
hit =(ImageButton)view.findViewById(R.id.imageButtonfa);
instrument =(ImageButton)view.findViewById(R.id.imageButtonga);
news =(ImageButton)view.findViewById(R.id.imageButtonha);
extras =(ImageButton)view.findViewById(R.id.imageButtonia);
playera =(ImageButton)view.findViewById(R.id.imageButtonaab);
playlista =(ImageButton)view.findViewById(R.id.imageButtoncab);
downloada =(ImageButton)view.findViewById(R.id.imageButtonbab);
streama =(ImageButton)view.findViewById(R.id.imageButtondab);
wisha =(ImageButton)view.findViewById(R.id.imageButtoneab);
hita =(ImageButton)view.findViewById(R.id.imageButtonfab);
instrumenta=(ImageButton)view.findViewById(R.id.imageButtongab);
newsa =(ImageButton)view.findViewById(R.id.imageButtonhab);
extrasa =(ImageButton)view.findViewById(R.id.imageButtoniab);
verticalSeekBar=(SeekBar)view.findViewById(R.id.seekBar);
ImageButton bP = (ImageButton) view.findViewById(R.id.left);
ImageButton bN = (ImageButton) view.findViewById(R.id.right);
bP.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//value 500 is arbitrarily given. if you want to achieve
//element-by-element scroll you should get the width of the
//previous element dynamically or if the elements of the
//list have uniform width just put that value instead
hsv.scrollTo(0,-500);
//if it's the first/last element you can bPrevoius.setEnabled(false)
}
});
bN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
hsv.scrollTo(500,0);
}
});
home.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Home");
Fragment Home = new Home();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, Home);
fragmentTransaction.addToBackStack(null);
// fragmentTransaction.popBackStack();
fragmentTransaction.commit();
// t.setText("Player");
}
});
player.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Player");
Fragment Myplayer = new MyPlayer();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, Myplayer);
fragmentTransaction.addToBackStack(null);
// fragmentTransaction.popBackStack();
fragmentTransaction.commit();
}
});
playlist.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// DrawerNavigation mainActivity = new DrawerNavigation();
// mainActivity.drawerLayout.closeDrawers();
Fragment yourPlayList = new Your_Playlist();
fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.containerView, yourPlayList);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
// t.setText("PlayList");
}
});
download.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("MyDownload");
Fragment myDownload = new Downloads();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,myDownload);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
stream.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Streaming");
Fragment uzBek1 = new UzBek();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,uzBek1);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
wish.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Your Wishes");
Fragment sendWishes = new wishes();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,sendWishes);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
hit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Hit Parade");
Fragment hitParade = new hits();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,hitParade);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
instrument.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Uzbek Instruments");
Fragment uzBek1 = new UzBek();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,uzBek1);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
news.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("News");
Fragment news = new news();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment,news);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
extras.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t.setText("Extras");
Fragment extras = new extras();
fragmentTransaction = getChildFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment, extras);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
return view;
}
}
Just add image buttons on both ends and seOnclickListener() on them then scroll them up to a desired value as shown in the code.

Categories

Resources