+ 1

Android Navigation Drawer Menu Selected Listener not working

I have a navigation drawer and i intend switch activity or display a toast whenever those are clicked but i can't because my MainActivity.java seems to have problem here is my code for that package com.example.universityportal; import android.content.Intent; import android.os.Bundle; import android.text.InputFilter; import android.text.TextUtils; import android.view.MenuItem; import android.view.View; import android.view.Menu; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.navigation.NavigationView; import com.google.android.material.textfield.TextInputEditText; import androidx.annotation.NonNull; import androidx.core.view.GravityCompat; import androidx.navigation.NavController; import androidx.navigation.Navigation; import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.NavigationUI; import androidx.drawerlayout.widget.DrawerLayout; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{ TextInputEditText userName, userPassword; Button registerBtn; private DrawerLayout mDrawerLayout; private AppBarConfiguration mAppBarConfiguration; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); EditText t= (EditText) findViewById(R.id.layout1); t.setMaxLines(1); InputFilter[] filterArray = new InputFilter[1]; filterArray[0] = new InputFilter.LengthFilter(12); t.setFilters(filterArray); //Defining our input fields in Java Button button1 = (Button) findViewById(R.id.button2); button1.setOnClickListen

29th Aug 2020, 11:24 AM
Timothy Njiru
Timothy Njiru - avatar
2 Réponses
+ 1
could you post the whole code in Playground and a link to it. mDrawerLayout is not initialized anywhere inside onCreate(). it's hard to see where the problem is without the whole code and the layouts xml.
29th Aug 2020, 12:21 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
Xml coming
29th Aug 2020, 1:12 PM
Timothy Njiru
Timothy Njiru - avatar