I want the user changes the text of a button many times he wants. To do that, he makes a long click in that button. This is the code:
@Override
public void onCreate(Bundle savedInstanceState) {
//blah blah
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage("Nueva Categoria:");
// Seting an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Button esteBoton = (Button) findViewById(R.id.button1);
String newCateg = input.getText().toString();
esteBoton.setText(newCateg);
}
});
Button button = (Button) findViewById(R.id.button1);
button.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
alert.show();
return true;
}
});
}
Ok. When I run this code in device simulator of Eclipse, there's no problem if it is the first time I enter text for the button 1 in the Alert Dialog, but the application crashes if I attempt to enter code for the second time. I am not expert in Java but I think this is due by the "final" attribute for "input", I can't change its value after once determined. How can I fix it ? The code is simple and I want to keep it in that way.