logo
down
shadow

Appropriate way to restart a navigation drawer fragment activity?


Appropriate way to restart a navigation drawer fragment activity?

By : NIS Class
Date : November 22 2020, 10:38 AM
Hope that helps I ended up showing a DialogFragment in the catch clause telling the user that the app needs to restart and by pressing the positive button I execute the same code that was in the previous catch clause... I sill don't get why the previous solution was giving me that strange behavior cause now I've get added a dialog and the app it's restarting as wanted..
code :


Share : facebook icon twitter icon
How to properly use the google maps fragment in a navigation drawer activity fragment

How to properly use the google maps fragment in a navigation drawer activity fragment


By : Shiva r
Date : March 29 2020, 07:55 AM
it fixes the issue You do not need to call (SupportMapFragment) (((FragmentActivity) getActivity()).getSupportFragmentManager() in your fragment as you have getFragmentManager() in Fragment. But when using Nested Fragments, you should use getChildFragmentManager() instead of getFragmentManager() (See documentation).
Coming to your question, you can simply update your code to this:
code :
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
if (mapFragment != null) {
    mapFragment.getMapAsync(this);
}
private View mContentView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mContentView == null) {
        mContentView = inflater.inflate(R.layout.content_locations, container, false);
    }
    return mContentView;
}
How to go to the fragment from different activity and that fragment which is the part of navigation drawer

How to go to the fragment from different activity and that fragment which is the part of navigation drawer


By : 张忠旺
Date : March 29 2020, 07:55 AM
wish of those help enter image description hereSomeone help me to solve this issue, struggling with activities and fragments but not able to understand it properly. I've a navigation drawer with , You may go from frangment to activity by using intent like this:
code :
Intent i = new Intent(getActivity(), YOURACTIVITY.class);
                startActivity(i)
@Override
    public void onBackPressed() {

        finish();
    }
How to keep the same fragment when activity restarts due to orientation change in a Navigation Drawer Activity

How to keep the same fragment when activity restarts due to orientation change in a Navigation Drawer Activity


By : lukas wet
Date : March 29 2020, 07:55 AM
it should still fix some issue Found my own answer and it it was a really simple thing after all. I left the solution here for those who are not familiar to android,like me .
code :
//current fragment
int fragment_id;

//make fragment selection available form the menu resource id
private void setFragment(MenuItem item) {

    Fragment fragment = null;
    fragment_id = item.getItemId();

    switch (fragment_id) {
        case R.id.nav_option_1:
            fragment = MyFragment1.newInstance(true);
            break;
        ...
        //Set fragment
        FragmentTransaction t = getSupportFragmentManager().beginTransaction();
        t.replace(R.id.content_navigation, fragment);
        t.commit();
    }

    item.setChecked(true);
}

private class DrawerItemClickListener implements NavigationView.OnNavigationItemSelectedListener {

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        setFragment(item);
        return false;
    }
}

//save the state
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(SAVE_INSTANCE_FRAGMENT_KEY, fragmentid);
}

//restore the saved fragment on create
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation);
    ///...
    if (savedInstanceState != null) {
        int fragment_id = savedInstanceState.getInt(SAVE_INSTANCE_FRAGMENT_KEY);
        selectItem(mDrawerList.getMenu().findItem(fragment_id));
    } else {
        selectItem(mDrawerList.getMenu().findItem(R.id.home_fragment_id));
    }

}
Android navigation drawer does not close when click outside the drawer (a fragment in main activity)

Android navigation drawer does not close when click outside the drawer (a fragment in main activity)


By : Bart
Date : March 29 2020, 07:55 AM
wish help you to fix your issue This happens because you NavigationDrawer is not capturing the view because the activity elements are not included in it, and to have it working properly, you have to make the NavigationDrawer is the main root of your Activity layout and the RelativeLayout is a child of it, like the following:
code :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar"
    tools:context=".MainActivity">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_orange_dark"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:title="Apartment Guide"
            app:titleTextColor="@android:color/white" />

        <FrameLayout
            android:id="@+id/fragment_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar">

        </FrameLayout>

    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="220dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/white"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/header"
        app:itemTextColor="@android:color/darker_gray"
        app:menu="@menu/drawer_menu" />

</android.support.v4.widget.DrawerLayout>
activity class intent into a specific fragment (fragment in a navigation drawer)

activity class intent into a specific fragment (fragment in a navigation drawer)


By : CAMMET
Date : March 29 2020, 07:55 AM
I wish this help you I was figure it out my answer.. instead of using the fragment transaction , i use intent
first, i was intent my activity to my navigation drawer and add a static String data (catch data)
code :
 private void checkCarts() {
        checkCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

               Intent i = new Intent(getApplicationContext(),EppDrawer.class);
               openSisame="okay";
               startActivity(i);



            }
        });
    }
try{
        if(EppItemPreviewPhone.openSisame.equals("okay")){
            displaySelectedScreen(2131296453);

        }
    }catch (Exception e){
        Toast.makeText(this, "NONE", Toast.LENGTH_SHORT).show();
        fragment=new EppMainFragment();
        if (fragment != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.frams, fragment);
            ft.commit();
        }

    }

  private void displaySelectedScreen(int itemId) {


    //initializing the fragment object which is selected
    switch (itemId) {
        case R.id.nav_home:
            fragment = new EppMainFragment();
            break;

        case R.id.nav_my_account:
            fragment = new EppMyAccount();
            break;
        case R.id.nav_view_cart:
            fragment = new EppViewCartV2();
            break;

        case R.id.nav_order:
            fragment = new EppOrderHistory();
            break;
        case R.id.nav_find:
            fragment = new EppFindProduct();
            break;
        case R.id.nav_about:
            fragment = new AboutFragment();
            break;
    }

    //replacing the fragment
    if (fragment != null) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.frams, fragment);
        ft.commit();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
}
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org