Alert Dialogue in Android-beginners -


i trying create simple alert dialogue , following steps link however,i getting error: getactivity() can't resolved after search understood getactivity() can user defined, not sure should make do.

here have:

public void about(view v1) {         alertdialog.builder builder = new alertdialog.builder(getactivity()); // add buttons         builder.setneutralbutton(r.string.close, new dialoginterface.onclicklistener() {             public void onclick(dialoginterface dialog, int id) {                 finish();//go previous activity             }         });  // set other dialog properties         builder.setmessage(r.string.myname);  // create alertdialog         alertdialog dialog = builder.create();} 
  • what wrong approach?
  • is there other better approach can suggest?
  • oh, , should getactivity() used for?

getactivity() fragments method activity. if u in activity u need replace youractivityclassname.this


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -