its a very silly question, but I started the program with java for android just a few days ago and I don’t know what to do ....
So, I want AlertDialog when you click the button. AlertDialog requires 2 Edits for this. when u click OK, he needs to calculate something and show the solution in the new AlertDialog.
here is what i got:
public void btn_own(View view) {
int a, b, c;
final String s;
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Enter range");
final EditText inputa = new EditText(this);
final EditText inputb = new EditText(this);
alert.setView(inputa);
alert.setView(inputb);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
int aa, bb, cc , e ;
aa = new Integer(String.valueOf(inputa));
bb = new Integer(String.valueOf(inputb));
cc = bb - aa;
Random rand = new Random();
int d = rand.nextInt(cc);
e = d + bb;
Integer out = new Integer(e);
s = out.toString();
new AlertDialog.Builder(this)
.setMessage(s)
.show();
}
});
}
The last "this" is invalid. I get a message:
Builder(android.content.Context) in Builder cannot be applied to (android.content.DialogInterface.OnClickListener)
but I don’t know what I can write instead of 'this'
Another problem is that 's' is marked in the line above 'this'.
Cannot assign a value to final variable 's'
I hope you can help me
EDIT:
My new code is:
public void btn_own(View view) {
int a, b, c;
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Enter range");
final EditText inputa = new EditText(this);
final EditText inputb = new EditText(this);
alert.setView(inputa);
alert.setView(inputb);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
int aa = 0;
int bb = 0;
int cc = 0;
int e = 0;
try {
aa = Integer.parseInt(inputa.getText().toString());
} catch (NumberFormatException f) {
System.out.println("not a number: " + inputa.getText().toString());
f.printStackTrace();
}
try {
bb = Integer.parseInt(inputb.getText().toString());
} catch (NumberFormatException g) {
System.out.println("not a number: " + inputb.getText().toString());
g.printStackTrace();
}
cc = bb - aa;
Random rand = new Random();
int d = rand.nextInt(cc);
e = d + bb;
Integer out = new Integer(e);
s = out.toString();
new AlertDialog.Builder(Decider.this)
.setMessage(s)
.show();
}
});
alert.show();
}
:
, : , .
: , ?
?