Giter Club home page Giter Club logo

Comments (11)

mxn21 avatar mxn21 commented on August 9, 2024

try to make setNavigationItemSelectedListener in MyMenuFragment$onCreateView.

@OverRide
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_menu, container,
false);
ivMenuUserProfilePhoto = (ImageView) view.findViewById(R.id.ivMenuUserProfilePhoto);
NavigationView vNavigation = (NavigationView) view.findViewById(R.id.vNavigation);
vNavigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@OverRide
public boolean onNavigationItemSelected(MenuItem menuItem) {
return false;
}
}) ;
setupHeader();
return setupReveal(view) ;
}

from flowingdrawer.

rhyodhan avatar rhyodhan commented on August 9, 2024

Thanks For Your Solution,
How can i call another fragment after use
" public boolean onNavigationItemSelected(MenuItem menuItem) {
return false;
} "; ?

i want to open another fragment after i chose drawer_menu.

from flowingdrawer.

vutiendung avatar vutiendung commented on August 9, 2024

the same question with @rhyodhan

from flowingdrawer.

moh586 avatar moh586 commented on August 9, 2024

the same question
how to set onnavigationitemselected listner in Activity that use mymenuFragment?

from flowingdrawer.

alafandiomar avatar alafandiomar commented on August 9, 2024

@vutiendung have u been able to solve it ??

from flowingdrawer.

moh586 avatar moh586 commented on August 9, 2024

@alafandiomar hi yes i was able to solve this problem.i declare an object of NavigationView in the MyMenuFragment and in the Main Activity i have declare a NavigationView.OnNavigationItemSelectedListener object that get the item clicked.
at the end i call mMenuFragment.vNavigation.setNavigationItemSelectedListener(navlistner); on toolbar onclick listener.i sent my file for better undrestanding
sorry for delay and bad english
MyMenuFragment.txt
MainActivity.txt

from flowingdrawer.

alafandiomar avatar alafandiomar commented on August 9, 2024

yes thank u very much i solved it too but by using fragments and interfaces .... if u want fragments instead of activities tell and ill send it to u :D @moh586 thanks

from flowingdrawer.

AhmedDonkl avatar AhmedDonkl commented on August 9, 2024

@alafandiomar could you please send me your solution using fragments and interfaces thanks

from flowingdrawer.

alafandiomar avatar alafandiomar commented on August 9, 2024

@AhmedDonkl sure thing when i get home :D

from flowingdrawer.

hemraj5 avatar hemraj5 commented on August 9, 2024

how to make left drawer items clickable .......

from flowingdrawer.

amit-upadhyay-IT avatar amit-upadhyay-IT commented on August 9, 2024

@moh586 : I would like to suggest a better way for the implementation of OnNavigationItemSelectedListener.

public class MyMenuFragment extends MenuFragment {

private ImageView ivMenuUserProfilePhoto;
public NavigationView navigationView;
private LeftDrawerLayout mLeftDrawerLayout;
AmitCallbackWhenDrawerOpens amitCallbackWhenDrawerOpens;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}


@Override
public void onAttach(Context context) {
    super.onAttach(context);
    amitCallbackWhenDrawerOpens = (AmitCallbackWhenDrawerOpens) context;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_menu, container,
            false);

    View view1 = inflater.inflate(R.layout.activity_main, container,
            false);
    mLeftDrawerLayout = (LeftDrawerLayout) view1.findViewById(R.id.id_drawerlayout);

    navigationView = (NavigationView) view.findViewById(R.id.vNavigation);

    //View navHeader = navigationView.getHeaderView(0); using when we are using support library greater than 23.0.0


    return  setupReveal(view) ;
}

public void onOpenMenu(){
    if (amitCallbackWhenDrawerOpens!= null)
        amitCallbackWhenDrawerOpens.drawerIsOpen();
    Toast.makeText(getActivity(),"onOpenMenu",Toast.LENGTH_SHORT).show();
}
public void onCloseMenu(){
    Toast.makeText(getActivity(),"onCloseMenu",Toast.LENGTH_SHORT).show();
}

public interface AmitCallbackWhenDrawerOpens {
    void drawerIsOpen();
}

}


public class MainActivity extends AppCompatActivity implements MyMenuFragment.AmitCallbackWhenDrawerOpens{

@OverRide
public void drawerIsOpen() {
mMenuFragment.navigationView.setNavigationItemSelectedListener(navlistner);
}
}

Benefits :

This enables the OnNavigationItemSelected even if someone slides the drawer

from flowingdrawer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.