0
Well, I’m learning android, I don’t know much. In this application, so far I just want to present the value of "name" in . Alertdialog setMessage, and I’m not sure how to do it, thanks in advance!
NOTE: When I run the app on my device, it appears
"Its name is:android.support.v7.widget.Appcompatedittext{...}"
package usuario.app.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;
import android.app.*;
import android.view.*;
public class ComprasActivity extends AppCompatActivity {
EditText nome, idade,cidade;
Button enviar;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compras);
nome = (EditText) findViewById(R.id.nome);
idade = (EditText) findViewById(R.id.idade);
cidade = (EditText) findViewById(R.id.cidade);
enviar = (Button)findViewById(R.id.enviar);
enviar.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
AlertDialog.Builder dialogo = new AlertDialog.Builder(ComprasActivity.this);
dialogo.setTitle("Seu perfil");
dialogo.setMessage("Seu nome é:" + nome);
dialogo.setNeutralButton("OK",null);
dialogo.show();
}
});
}
}
I was about to reply but you anticipated it. However your answer is not completely correct.
– ramaral
@ramaral Forget something?
– Isac
Not exactly, because in this case it works. But the "most correct" would be to use
nome.getText().toString()
.– ramaral
Thank you very much. The start is never easy, thanks for the help.
– Igor
@ramaral Yes I did, but I ended up walking back and pulled out to be simpler. But in several other places it is necessary a
String
it has to be the way it indicated, sincegetText
return acharSequence
and not aString
– Isac
It may be simpler but the AP (which is still learning) will be confused when using only
getText()
when assigning to a variable String type and error.– ramaral
@ramaral Yes you are right, I can complete the answer with that reference, to help in the future in other similar situations.
– Isac