Onclick listener for navigation bar

honeyasin

New member
Jan 20, 2018
2
0
0
Visit site
I have developed an android application using java and [link removed] studio. But when I click the items in the navigation drawer, I expect it to display a dialog, but nothing happens. Also when I try to setText in the drawer, the application crashes. I'm new to android development. Please help me on this

Below is my code:

private TextView name;
public TextView email;
public TextView contact;
private DrawerLayout drawerLayout;
AlertDialog.Builder builder;
private ActionBarDrawerToggle actionBarDrawerToggle;
@override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerLayout=(DrawerLayout) findViewById(R.id.drawer);
builder=new AlertDialog.Builder(MainActivity.this);
name=(TextView) findViewById(R.id.myname);
email=(TextView) findViewById(R.id.myemail);
contact=(TextView) findViewById(R.id.mycontact);

actionBarDrawerToggle=new ActionBarDrawerToggle(this, drawerLayout,R.string.open,R.string.close);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

//RECEIVING THE INTENT
/* Get values from Intent
Intent intent = getIntent();
String myname = intent.getStringExtra("dname");
String myemail = intent.getStringExtra("demail");
String mycontact = intent.getStringExtra("dcontact");

name.setText(myname);
email.setText(myemail);
contact.setText(mycontact);

builder.setTitle("Log In Successful");
builder.setMessage("Welcome, "+myname);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@override
public void onClick(DialogInterface dialog, int which) {
//Toast.makeText(getApplicationContext(),"Clock Out Cancelled",Toast.LENGTH_SHORT).show();
}
});
AlertDialog alertDialog=builder.create();
alertDialog.show();*/
//name.setText(response);
/*try {

Thank You
Honey Asin
 
Last edited by a moderator: