Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two different activities, A & B. Both have NavigationDrawer , look alike, but not are the same, because I could not get the drawer layout ID of activity A in activity B.

Both activity has 3 fragments each (total 6).

The NavigationDrawer contains all fragments of activity class A only. My problem is, when I am in activity B, and try to open one fragment of activity A from navigation drawer, it throws an error

No view found for id 0x7f090047 (com.wlodsgn.bunbunup:id/linear) for fragment FmMenu{b1e537f0 #0 id=0x7f090047}

How do I achieve it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have created an intent inside the second activity and started the activity A with information about the fragment to be called.

Intent i = new Intent(this, ActivityClass.class);
i.putExtra("frgToLoad", "FRAGMENT_A");
startActivity(i);

Now, inside activity A, checked the extra and load the right Fragment:

OnCreate(){
...
if (getIntent().getExtras() != null) {
String intentFragment = getIntent().getExtras().getString("frgToLoad");

switch (intentFragment){
    case "FRAGMENT_A":
        // Load corresponding fragment
        break;
    case "FRAGMENT_B":
        // Load corresponding fragment
        break;
    case "FRAGMENT_C":
        // Load corresponding fragment
        break;
   }
}
}

One have to check if intent is null or not before I try to assign a value to intentFragment. This is because that line of code is called whether I am coming from activity B or not, and it will throw error if intent is null.

credit : https://stackoverflow.com/a/36064344/3380537


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...