Loading a fragment upon a specific condition
I have an issue please help me out. I am building an android application and I have successfully integrated Rewarded video ads to it.
I want to show a fragment or auto redirect to a specific fragment when the below condition is met:
@Override
public void onRewarded(RewardItem rewardItem) {
// I want to redirect the user to a particular fragment here.
}
So Please help me out, if there is any other way to achieve this then please let me know.


add a comment |
I have an issue please help me out. I am building an android application and I have successfully integrated Rewarded video ads to it.
I want to show a fragment or auto redirect to a specific fragment when the below condition is met:
@Override
public void onRewarded(RewardItem rewardItem) {
// I want to redirect the user to a particular fragment here.
}
So Please help me out, if there is any other way to achieve this then please let me know.


So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?
– Piyush
Nov 21 '18 at 11:13
I am just starting out with android kindly help me.
– Syed Naveed
Nov 21 '18 at 11:14
Check this
– Piyush
Nov 21 '18 at 11:15
Possible duplicate of having a condition to fragment adding
– Hossam Hassan
Nov 21 '18 at 11:22
add a comment |
I have an issue please help me out. I am building an android application and I have successfully integrated Rewarded video ads to it.
I want to show a fragment or auto redirect to a specific fragment when the below condition is met:
@Override
public void onRewarded(RewardItem rewardItem) {
// I want to redirect the user to a particular fragment here.
}
So Please help me out, if there is any other way to achieve this then please let me know.


I have an issue please help me out. I am building an android application and I have successfully integrated Rewarded video ads to it.
I want to show a fragment or auto redirect to a specific fragment when the below condition is met:
@Override
public void onRewarded(RewardItem rewardItem) {
// I want to redirect the user to a particular fragment here.
}
So Please help me out, if there is any other way to achieve this then please let me know.




edited Nov 21 '18 at 11:19


Fantômas
32.6k156389
32.6k156389
asked Nov 21 '18 at 11:11
Syed NaveedSyed Naveed
398
398
So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?
– Piyush
Nov 21 '18 at 11:13
I am just starting out with android kindly help me.
– Syed Naveed
Nov 21 '18 at 11:14
Check this
– Piyush
Nov 21 '18 at 11:15
Possible duplicate of having a condition to fragment adding
– Hossam Hassan
Nov 21 '18 at 11:22
add a comment |
So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?
– Piyush
Nov 21 '18 at 11:13
I am just starting out with android kindly help me.
– Syed Naveed
Nov 21 '18 at 11:14
Check this
– Piyush
Nov 21 '18 at 11:15
Possible duplicate of having a condition to fragment adding
– Hossam Hassan
Nov 21 '18 at 11:22
So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?
– Piyush
Nov 21 '18 at 11:13
So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?
– Piyush
Nov 21 '18 at 11:13
I am just starting out with android kindly help me.
– Syed Naveed
Nov 21 '18 at 11:14
I am just starting out with android kindly help me.
– Syed Naveed
Nov 21 '18 at 11:14
Check this
– Piyush
Nov 21 '18 at 11:15
Check this
– Piyush
Nov 21 '18 at 11:15
Possible duplicate of having a condition to fragment adding
– Hossam Hassan
Nov 21 '18 at 11:22
Possible duplicate of having a condition to fragment adding
– Hossam Hassan
Nov 21 '18 at 11:22
add a comment |
2 Answers
2
active
oldest
votes
Use Fragment Manager and Fragment Transaction Manager for this.
getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();
Thanks it helped!
– Syed Naveed
Nov 21 '18 at 15:34
add a comment |
Write below code inside your onRewarded :
android.support.v4.app.Fragment fragment = new FragmentA();
android.support.v4.app.FragmentManager fragmentManager = getActivity()
.getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.
I am mentioning a sample activity with a framelayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Below is a fragment Container" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_height="wrap_content"
android:layout_width="match_content" />
</LinearLayout>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410872%2floading-a-fragment-upon-a-specific-condition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use Fragment Manager and Fragment Transaction Manager for this.
getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();
Thanks it helped!
– Syed Naveed
Nov 21 '18 at 15:34
add a comment |
Use Fragment Manager and Fragment Transaction Manager for this.
getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();
Thanks it helped!
– Syed Naveed
Nov 21 '18 at 15:34
add a comment |
Use Fragment Manager and Fragment Transaction Manager for this.
getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();
Use Fragment Manager and Fragment Transaction Manager for this.
getFragmentManager().beginTransaction().replace(R.id.your_framelayout_id, new your_fragment()).commit();
answered Nov 21 '18 at 11:20


Sam.Sam.
412410
412410
Thanks it helped!
– Syed Naveed
Nov 21 '18 at 15:34
add a comment |
Thanks it helped!
– Syed Naveed
Nov 21 '18 at 15:34
Thanks it helped!
– Syed Naveed
Nov 21 '18 at 15:34
Thanks it helped!
– Syed Naveed
Nov 21 '18 at 15:34
add a comment |
Write below code inside your onRewarded :
android.support.v4.app.Fragment fragment = new FragmentA();
android.support.v4.app.FragmentManager fragmentManager = getActivity()
.getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.
I am mentioning a sample activity with a framelayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Below is a fragment Container" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_height="wrap_content"
android:layout_width="match_content" />
</LinearLayout>
add a comment |
Write below code inside your onRewarded :
android.support.v4.app.Fragment fragment = new FragmentA();
android.support.v4.app.FragmentManager fragmentManager = getActivity()
.getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.
I am mentioning a sample activity with a framelayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Below is a fragment Container" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_height="wrap_content"
android:layout_width="match_content" />
</LinearLayout>
add a comment |
Write below code inside your onRewarded :
android.support.v4.app.Fragment fragment = new FragmentA();
android.support.v4.app.FragmentManager fragmentManager = getActivity()
.getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.
I am mentioning a sample activity with a framelayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Below is a fragment Container" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_height="wrap_content"
android:layout_width="match_content" />
</LinearLayout>
Write below code inside your onRewarded :
android.support.v4.app.Fragment fragment = new FragmentA();
android.support.v4.app.FragmentManager fragmentManager = getActivity()
.getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction =
fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
Here fragment_container is a FrameLayout defined inside your Activity on which you want to host your fragment.
I am mentioning a sample activity with a framelayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Below is a fragment Container" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_height="wrap_content"
android:layout_width="match_content" />
</LinearLayout>
answered Nov 21 '18 at 11:31


Chandrani ChatterjeeChandrani Chatterjee
705316
705316
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410872%2floading-a-fragment-upon-a-specific-condition%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So what is the issue ? Don't you aware of FragmentTransaction with FragmentManager?
– Piyush
Nov 21 '18 at 11:13
I am just starting out with android kindly help me.
– Syed Naveed
Nov 21 '18 at 11:14
Check this
– Piyush
Nov 21 '18 at 11:15
Possible duplicate of having a condition to fragment adding
– Hossam Hassan
Nov 21 '18 at 11:22