开发者

Access to TextView in ViewPager

I have a ViewPager in my main Activity and make a TextView on every page.

@Override
    public Object instantiateItem(View collection, int counterID) {
        TextView counter = new TextView(cxt);
        ((ViewPager) collection).addView(counter, 0);
        retu开发者_如何学JAVArn counter;
    }

TextView shows counter value and I want to change it on active page (TextView text) using the method I implemented in the same Activity with PagerAdapter.

Is there any way to access TextView on specific page outside of PagerAdapter (in the same Activity) and change its attributes?


You can set an ID to the TextView by calling

textview.setId(int id);

Then you can find your view by (TextView) findViewById(int id)

or you can set a Tag on the textview:

textview.setId(Object tag); and find the view via (TextView) findViewWithTag (Object tag)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜