简体   繁体   中英

Android- How to recreate a CustomView in ActionBar?

I have a activity that implements a CustomView to inflate the ActionBar with a Checkbox. This Checkbox is a "LikeButton" to a article from a source and when the user swipe from left/right it load another articles from the same source.

The code is working fine for the first article that the user open, but when he swipe the Checkbox stays with the same state from the firt article.

How can I build a CustomView diferent for every article and inflate it when the user swipe?

Use a ViewPager with Fragments containing your custom views. Also, for each fragment, make sure that you enable it's own options menu by calling Fragment.setHasOptionsMenu(boolean hasMenu); . Once your do this, just Override your optionsMenu methods within your fragment classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM