Set value in textview

Asked

Viewed 559 times

0

Basically I’m not getting to set the value in the field.

I’m doing so, I declared the variables:

    Restaurante restaurante;

@ViewById
TextView nmRestaurante;

@ViewById
ImageView imgLogoRestaurante;

@ViewById
RatingBar ratingBar;

@ViewById
ListView lisComentarios;

@ViewById
LinearLayout lytEmptyComentarios;


List<Comentarios> lstComentarios;

GenericAdapter<Comentarios> adapter;

Then the method onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_comentarios);
    restaurante = Globales.getRestauranteAtual();
    View v = findViewById(R.id.toolbar_title);

    nmRestaurante = (TextView) findViewById(R.id.nmRestaurante);
    imgLogoRestaurante = (ImageView) findViewById(R.id.imgLogoRestaurante);
    ratingBar = (RatingBar) findViewById(R.id.ratingBar);

    lisComentarios = (ListView) findViewById(R.id.lisComentarios);
    lytEmptyComentarios = (LinearLayout) findViewById(R.id.lytEmptyComentarios);

    TextView toolbarTitle = (TextView) v;
    toolbarTitle.setText(restaurante.getNomeRestaurante());

    nmRestaurante.setText(restaurante.getNomeRestaurante());
    Picasso.with(getApplicationContext()).load(restaurante.getUrlImagem()).into(imgLogoRestaurante);

    ratingBar.setRating(Float.valueOf(String.valueOf(restaurante
            .getMedia())));

    carregarComentarios(restaurante.getCodigoRestaurante());
}

In no error log, and still the fields turn white

I’m sure you’re getting the data inserir a descrição da imagem aqui

  • Probably restaurante.getNomeRestaurante() is returning a String empty.. would have to see where you carry the entity..

  • I used the break point and I saw that it was coming, I put in the variable restaurant aprti from here restaurante = Globales.getRestauranteAtual();&#xA; restaurante = Globales.getRestauranteAtual();

  • Perhaps then the position of TextView is not appearing in the View, or is under some other component... tries to "set" a fixed text in the XML and just load the layout with setContentView and see if it shows up...

  • When Seto in XML it appears normally, then it is nothing blocking. this very strange all this...

1 answer

3


I believe that it may be giving some problem of you using the @Viewbyid Annotation and then in the code is giving a findViewById.

Try to remove the Annotation and tell us what happened.

-- EDIT--

The error occurred because when using the @Viewbyid Annotation, the views are not instantiated in the onCreate() method, according to documentation.

https://github.com/androidannotations/androidannotations/wiki/Injecting-Views

And as he was using the findViewById method the Annotation was having no use at all in the code.

To use Annotation it should use the @Afterviews method, e.g.:

@AfterViews
void preencheDados() {
    //Preenche as view que estavam com @ViewById.
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.