Java – different titles for each fragment in my viewpager

I'm using a viewpager "tab slide" and I want to set a different title for each clip in the actionbar so that the title changes when I switch@ H_ 301_ 2 @ I tried several things without success. Only the last title shows... When I switch, it won't change

Solution

First, let your activity implement an onpagechangelistener@ H_ 301_ 2@ then, when you create a viewpager, you can use mviewpager Setonpagechangelistener (this) so that your activity will receive a callback when the page changes

@Override
public abstract void onPageSelected(int position) {
    setTitle(getTitleFromPosition(position));
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>