0

I am trying to set Text in navigation drawer through main class after user successfully logs in. It is working fine when I use the below code:

 if(LoggedFlag==1) {
        setContentView(R.layout.activity_home_logged);

    }
    else{
        setContentView(R.layout.activity_home);
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Home.this, AddTrek.class);
            startActivity(intent);
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();


    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    /*View hd = navigationView.inflateHeaderView(R.layout.nav_header_home);
    tvNavName = (TextView)hd.findViewById(R.id.tv_nav_name);
    tvNavName.setText("hello");*/

But when I uncomment the setText part and run, I get two drawers one with the text that is set in xml file, and other with the text "hello". what changes do I have to make here to get only one drawer with the text that I pass through main class.

ManishPrajapati
  • 459
  • 1
  • 5
  • 16

0 Answers0