Fernando
Fernando

Reputation: 43

Changes the text of a textview from a new event [Android]

I can't change the text of text_view_cantidad_resultados of aTextView` from an event. This is the code:

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

    text_view_cantidad_resultados = (TextView) findViewById(R.id.text_view_cantidad_resultados);
    viewPager = (ViewPager) findViewById(R.id.view_pager_cards_resultados);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            Log.d("onPageSelected: ", String.valueOf(position));
             /*Here is where a want to changes the text of          
             text_view_cantidad_resultados.
             Something like                     
             text_view_cantidad_resultados.setText(position);
             */
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}

I know that is because that object is not defined in that instance of the class (in the event), but a have no idea of how can I do it.

Upvotes: 2

Views: 58

Answers (1)

Muthukrishnan Rajendran
Muthukrishnan Rajendran

Reputation: 11622

TextView will accept only int value as resource, so convert your int to String add it will work,

Ex:

text_view_cantidad_resultados.setText(position + "");

or

text_view_cantidad_resultados.setText(String.valueOf(position));

Upvotes: 1

Related Questions