Mathematical operation onBindViewHolder

Asked

Viewed 74 times

0

I’m trying to do a mathematical operation by taking a number of Child in the firebase, more often than not the error of converting string... the getCounter this as Stringno model , more when I change it to int,long or Double it gives the error that you can’t convert string... Thank you in advance.

@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) 
{

    final Blog blog = mQuestionList.get(position);
    int conta01 = Integer.parseInt(blog.getCounter());
    int conta02 = 5;
    int resultado = conta01-conta02;

    holder.new_post.setText(resultado);

android.content.res.Resources$Notfoundexception: String Resource ID #0xfffffffd at android.content.res.resources.gettext(Resources.java:327) at android.widget.Textview.setText(Textview.java:4663) with.robertoc.meublogclash.AdapterRecyclerView.Recyclerviewamigos.onBindViewHolder(Recyclerviewamigos.java:97) with.robertoc.meublogclash.AdapterRecyclerView.Recyclerviewamigos.onBindViewHolder(Recyclerviewamigos.java:32) at android.support.v7.widget.Recyclerview$Adapter.onBindViewHolder(Recyclerview.java:6356) at android.support.v7.widget.Recyclerview$Adapter.bindViewHolder(Recyclerview.java:6389) at android.support.v7.widget.Recyclerview$Recycler.tryBindViewHolderByDeadline(Recyclerview.java:5335) at android.support.v7.widget.Recyclerview$Recycler.tryGetViewHolderForPositionByDeadline(Recyclerview.java:5598) at android.support.v7.widget.Recyclerview$Recycler.getViewForPosition(Recyclerview.java:5440) at android.support.v7.widget.Recyclerview$Recycler.getViewForPosition(Recyclerview.java:5436) at android.support.v7.widget.Linearlayoutmanager$Layoutstate.next(Linearlayoutmanager.java:2224) at android.support.v7.widget.Linearlayoutmanager.layoutChunk(Linearlayoutmanager.java:1551) at android.support.v7.widget.Linearlayoutmanager.Fill(Linearlayoutmanager.java:1511)

1 answer

2


It is giving error because in the method setText, if you pass an integer value, it understands that it is to take the value of a Resource with that id (which probably won’t exist, so the error). If you want to write the integer value, you have to convert it to String. You can do so:

holder.new_post.setText("" + resultado);

Browser other questions tagged

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