Set value in textview

0

I'm basically not able to set the value in the field.

I'm doing this, declare 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 the log there is no error, and even then the fields are white

I'm sure you're having the data

    
asked by anonymous 14.06.2017 / 13:51

1 answer

3

I think it might be giving you some trouble to use the annotation @ViewById and then the code will be giving a findViewById.

Try removing the annotation and tell us what happened.

- EDIT -

The error happened because when using the annotation of @ViewById, the views are not instantiated in the onCreate () method, according to documentation.

link

And as it was using the findViewById method annotation was not having any use in the code.

To use annotation, you should use the @AfterViews method, eg:

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