1
I’m a beginner in android and the max that I managed to do so far is to press the save button it prints in the log that I wrote, but I’m not able to store this in a variable.
package com.example.igor.blocodenotas;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;
/**
* Created by Igor on 19/05/2016.
*/
public class Dialogobox extends DialogFragment{
@Override
public Dialog onCreateDialog(Bundle saveInstanceState){
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
builder.setTitle("Insira sua anotação:");
// DECLARACAO DO EDITTEXT
final EditText anotacao = new EditText(getActivity());
builder.setView(anotacao);
builder.setNegativeButton(R.string.cancelar,new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which){
Toast.makeText(getActivity(),"você clicou em cancelar",Toast.LENGTH_SHORT).show();
}
});
builder.setPositiveButton(R.string.salvar,new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which){
Log.v("EditText",anotacao.getText().toString());
}
});
Dialog dialog=builder.create();
return dialog;
}
}
Declare a variable of type String and then to store use:
nomeVariavel = anotacao.getText().toString();
– ramaral
I managed, thank you, I was trying this way but putting the name of the variable note also so it did not work
– Igor Oliveira