How to display a parse String in a Textview? [closed]

2

I'm trying to add an image with a description on the parse server. I have already been able to add the description of the image by objectId , but the problem is that I do not know how to display the text of the image in a textview .

Any help will be welcome.

package com.parse.starter.Activity;

public class descricaoActivity extends AppCompatActivity {

    private EditText textoDescricao;
    private Button descricaoBotao;
    private TextView descricao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_descricao);

        textoDescricao = (EditText) findViewById(R.id.editTextDescricao);
        descricao = (TextView) findViewById(R.id.descricaoId);
        descricaoBotao = (Button) findViewById(R.id.botaoDescricaoId);

        descricaoBotao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Recupera o objectId da imagem
                Bundle extra = getIntent().getExtras();
                final String objetoId = extra.getString("idObjeto");

                //Recupera o texto digitado pelo usuário
                final String textoDigitado = textoDescricao.getText().toString();

                //Monta o objeto para ser salvo no Parse
                ParseObject parseObject = new ParseObject("Imagem");
                parseObject.setObjectId(objetoId);
                parseObject.put("Nome", textoDigitado);

                //Salva a descrição no objectId da imagem
                parseObject.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e == null) { //Sucesso
                            Toast.makeText(getApplicationContext(),
                                           "Sua descrição foi publicada!",
                                           Toast.LENGTH_LONG).show();

                            Intent intent = new Intent(getApplicationContext(),
                                                       MainActivity.class);
                            startActivity(intent);
                            finish();

                        } else { //Erro
                            Toast.makeText(getApplicationContext(),
                                           "Erro ao postar sua descrição, tente novamente!",
                                           Toast.LENGTH_LONG).show();
                        }
                    }
                });
            }
        });
    }
}
    
asked by anonymous 19.01.2017 / 19:28

1 answer

1

To set a text in TextView you must use setText . See below:

TextView descricao = (TextView) findViewById(R.id.descricaoId);
descricao.setText("As vezes é simples!");

You have to observe how the description in parse is defined, for example parseObject.getString("descricao"); . So you can do it this way:

descricao.setText(parseObject.getString("descricao"));

See other properties of TextView in documentation.

    
19.01.2017 / 21:02