Reputation: 87
i have an activity with a toolbar, a tablayout and a pager. So with the toolbar i have the name of the app and maybe i can add some button for navigation.
With the tablayout i can click or just move the finger left or right to navigate throw my 3 fragment.
In a fragment i put a button, and it purposes is to show a fragment over all my layout. So everything i said before will be all covered by this fragment.
How can i realize that? I saw many videos and guide, but my button wont work. I dont even get any error and my app start well. While testing, if i click the button nothing happened. In the "run" doesnt show any information, like the button is empty.
public void onClick(View v) {
switch(v.getId()){
case R.id.button2:
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(v.getContext(), CheckActivity.class));
getActivity().finish();
break;
case R.id.button3:
EditProfileFragment editprofiele = new EditProfileFragment();
getFragmentManager().beginTransaction().replace(R.id.MainAct, editprofiele).commit();
break;
default:
break;
}
}
I have two button. The button2 is for disconnect and open a new activity. The button3 is for showing up my fragment. I tried any combination. Maybe not replace but add, and something else. But everything isnt working.
In the activity that holds everythings i have already implements the listener to that fragment. any help?
Upvotes: 0
Views: 1304
Reputation: 395
onButtonClick open fragment...My button is on fragment was having same issue.
AppCompatActivity activity = (AppCompatActivity) view.getContext();
YourFragment yourFragment = new YourFragment();
activity.getSupportFragmentManager().beginTransaction()
.replace(R.id.frameLayoutMaps, myFragment)
.addToBackStack(null)
.attach(myFragment)
.commit();
add frameLayout in your Activity
<FrameLayout
android:id="@+id/frameLayoutMaps"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
in MainLayout of YourFragment in xml add android:clickable="true"
Hope this helps.
Upvotes: 1