Navigationview click event doesn’t work in Android. I click to item-element but the codes doesn’t work. The Java and XML Codes are in below.
Codes:
menulayout = (DrawerLayout)findViewById(R.id.drawerlayout);
navview = (NavigationView)findViewById(R.id.navview);
navview.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener () {
public boolean onNavigationItemSelected(MenuItem secilen){
Toast.makeText(getApplicationContext(), "tıklandı" + secilen, Toast.LENGTH_LONG).show();
if(secilen.getItemId() == R.id.profilitem){
startActivity(new Intent(getApplicationContext(), profil.class));
}else if(secilen.getItemId() == R.id.haberitem){
startActivity(new Intent(getApplicationContext(), haber.class));
}else if(secilen.getItemId() == R.id.cashgonderitem){
startActivity(new Intent(getApplicationContext(), cashgonder.class));
}else if(secilen.getItemId() == R.id.cashalitem){
startActivity(new Intent(getApplicationContext(), cashal.class));
}else if(secilen.getItemId() == R.id.ayaritem){
startActivity(new Intent(getApplicationContext(), ayar.class));
}else if(secilen.getItemId() == R.id.yardimitem){
startActivity(new Intent(getApplicationContext(), yardim.class));
}
return false;
}
});
XML Code :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".navdraweroyun"
android:fitsSystemWindows="true"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<include
layout="@layout/activity_oyunbar"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/navmenu"
/>
</android.support.v4.widget.DrawerLayout>
I hope I haven't a error in XML.
How I can resolve this problem?
I hope you are understand. I doesn't have a good English.
I need your help.