Android: while i select an item from navigation drawer, it is not moving to the new screen -
when set size of viewerpage want output image
i set tabs
in home footer menu. code follow:
home.java
package com.example.sachin.omcommunication; import android.app.fragmentmanager; import android.content.intent; import android.os.bundle; import android.support.design.widget.navigationview; import android.support.design.widget.tablayout; import android.support.v4.app.fragment; import android.support.v4.app.fragmentpageradapter; import android.support.v4.app.fragmenttransaction; import android.support.v4.view.gravitycompat; import android.support.v4.view.viewpager; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbardrawertoggle; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.menu; import android.view.menuitem; import java.util.arraylist; import java.util.list; public class home extends appcompatactivity implements navigationview.onnavigationitemselectedlistener { private toolbar toolbar; private tablayout tablayout; private viewpager viewpager; fragment newfragment; fragmentmanager mfragmentmanager; fragmenttransaction mfragmenttransaction; private int[] tabicons = { r.mipmap.ic_launcher, r.mipmap.ic_launcher, r.mipmap.ic_launcher, r.mipmap.ic_launcher }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_home); toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); getsupportactionbar().setdisplayhomeasupenabled(true); viewpager = (viewpager) findviewbyid(r.id.viewpager); setupviewpager(viewpager); tablayout = (tablayout) findviewbyid(r.id.tabs); tablayout.setupwithviewpager(viewpager); setuptabicons(); fragmenttransaction fragmenttransaction = getsupportfragmentmanager().begintransaction(); fragmenttransaction.replace(r.id.framelayout, new homepage()); fragmenttransaction.commit(); 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); } private void setuptabicons() { tablayout.gettabat(0).seticon(tabicons[0]); tablayout.gettabat(1).seticon(tabicons[1]); tablayout.gettabat(2).seticon(tabicons[2]); tablayout.gettabat(3).seticon(tabicons[3]); } private void setupviewpager(viewpager viewpager) { viewpageradapter adapter = new viewpageradapter(getsupportfragmentmanager()); adapter.addfragment(new homepage(), "one"); adapter.addfragment(new twofragment(), "two"); adapter.addfragment(new threefragment(), "three"); adapter.addfragment(new fourfragment(), "four"); viewpager.setadapter(adapter); } class viewpageradapter extends fragmentpageradapter { private final list<android.support.v4.app.fragment> mfragmentlist = new arraylist<>(); private final list<string> mfragmenttitlelist = new arraylist<>(); public viewpageradapter(android.support.v4.app.fragmentmanager manager) { super(manager); } @override public android.support.v4.app.fragment getitem(int position) { return mfragmentlist.get(position); } @override public int getcount() { return mfragmentlist.size(); } public void addfragment(android.support.v4.app.fragment fragment, string title) { mfragmentlist.add(fragment); mfragmenttitlelist.add(title); } @override public charsequence getpagetitle(int position) { return null; } } @override public void onbackpressed() { drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); if (drawer.isdraweropen(gravitycompat.start)) { drawer.closedrawer(gravitycompat.start); } else { super.onbackpressed(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.home, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_logout) { intent = new intent(getapplicationcontext(), login.class); startactivity(i); return true; } else if (id == r.id.action_exit) { finish(); return true; } return super.onoptionsitemselected(item); } @suppresswarnings("statementwithemptybody") @override public boolean onnavigationitemselected(menuitem item) { // handle navigation view item clicks here. int id = item.getitemid(); if (id == r.id.nav_home) { // handle action fragmenttransaction fragmenttransaction = getsupportfragmentmanager().begintransaction(); fragmenttransaction.replace(r.id.framelayout, new homepage()); fragmenttransaction.commit(); } else if (id == r.id.myvisit) { fragmenttransaction fragmenttransaction = getsupportfragmentmanager().begintransaction(); fragmenttransaction.replace(r.id.framelayout, new visit()); fragmenttransaction.commit(); } else if (id == r.id.myorder) { fragmenttransaction fragmenttransaction = getsupportfragmentmanager().begintransaction(); fragmenttransaction.replace(r.id.framelayout, new order()); fragmenttransaction.commit(); } else if (id == r.id.mypaymnet) { fragment newfragment = new payment(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); } else if (id == r.id.mydelivery) { fragment newfragment = new delivery(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); } else if (id == r.id.dailytask) { fragment newfragment = new addtask(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); } else if (id == r.id.scheduletask) { fragment newfragment = new scheduletask(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); } else if (id == r.id.onetimetask) { fragment newfragment = new onetimetask(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); } else if (id == r.id.myattendence) { fragment newfragment = new attendence(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); } else if (id == r.id.lapp) { fragment newfragment = new leaveapplication(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); } else if (id == r.id.profile) { fragment newfragment = new profile(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); } else if (id == r.id.action_logout) { fragment newfragment = new homepage(); fragmenttransaction fragmentmanager= getsupportfragmentmanager().begintransaction(); fragmentmanager.commit(); return true; } drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout); drawer.closedrawer(gravitycompat.start); return true; } }
now, want move homepage
screen while select home in navigation drawer.
homepage.java
package com.example.sachin.omcommunication; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; public class homepage extends fragment { public homepage(){} view view; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.activity_visit, container, false); getactivity().settitle("homepage"); return inflater.inflate(r.layout.activity_home_page, container, false); } }
here, posted layout
content_home.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/themeoverlay.appcompat.dark.actionbar"> <!-- <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorprimary" app:layout_scrollflags="scroll|enteralways" app:popuptheme="@style/themeoverlay.appcompat.light" /> --> <include android:layout_height="match_parent" layout="@layout/toolbar" android:layout_width="wrap_content" android:id="@+id/toolbar" ></include> <android.support.v4.view.viewpager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#ffffff" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <android.support.design.widget.tablayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabmode="fixed" app:tabgravity="fill"/> </android.support.design.widget.appbarlayout> <framelayout android:id="@+id/framelayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" > </framelayout> </linearlayout>
as same homepage.java
set other .java
files
navigationview.setnavigationitemselectedlistener(new navigationview.onnavigationitemselectedlistener() { // method trigger on item click of navigation menu @override public boolean onnavigationitemselected(menuitem menuitem) { //checking if item in checked state or not, if not make in checked state if (menuitem.ischecked()) menuitem.setchecked(false); else menuitem.setchecked(true); //closing drawer on item click drawerlayout.closedrawers(); //check see item being clicked , perform appropriate action switch (menuitem.getitemid()) { //replacing main content contentfragment our inbox view; case r.id.drawer_how: fragmenttransaction fragmenttransaction = getsupportfragmentmanager().begintransaction(); fragmenttransaction.replace(r.id.framelayout, new homepage()); fragmenttransaction.commit(); return true; // rest of options show toast on click ..... default: toast.maketext(getapplicationcontext(), "somethings wrong", toast.length_short).show(); return true; } } });
Comments
Post a Comment