Remove the inner class, use it just as a function inside your activity.
public void AlertShow()
{
Context mContext = this;
LayoutInflater inflater = getLayoutInflater();
View alertLayout = inflater.inflate(R.layout.layout_custom_dialog, null);
final EditText name = (EditText) alertLayout.findViewById(R.id.et_name);
//final EditText track = (EditText) alertLayout.findViewById(R.id.et_track);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Add track number");
//alert.setIcon(R.drawable.plus);
alert.setView(alertLayout);
alert.setCancelable(false);
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(mContext, "Abort", Toast.LENGTH_SHORT).show();
}
});
alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String sname = name.getText().toString();
//String track = etPassword.getText().toString();
Toast.makeText(mContext, "Name: " + sname +" "+ " Track: " , Toast.LENGTH_SHORT).show();
}
});
AlertDialog dialog = alert.create();
dialog.show();
}
Then to call it:
AlertShow();