I have write a multi-level Preferences in program with xml File. and i want to know how to return to the previous level without press the back button. how to write some code to implement an item in preference to return previous Preferences level.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I had the same problem and solve it thanks to Xuelong and getDialog() but without needing to manage onPreferenceTreeClick().
You will then return from where you came from.
Here is a epurated example :
Xml file :
Java file :
That's it
Sorry for presentation, this is my first post on this site.
Bye dudes
I think you are looking for something like this
But what I didnt get is that your want to return to the previous preference screen, without pressing back button. Can you shed some more light on that??
You can simulate the press of the back button:
or
if you are in a fragment.
Building on Patrice's and Xuelong's answers, I have made the following functions to easily do the job:
So first if what you do in your submenu define what is shown on the parent menu (eg in a music app: submenu allows to add a new instrument, and the parent menu shows the list of added instruments), you first have to call
refreshPreferenceScreenByClick("parentPreferenceScreen")
, and then to go back to the parent menu you can just close the current submenu by callingclosePreferenceScreen("currentPreferenceScreen")
.Alternatively, if you want to just open a submenu programmatically, you can use the openPreference function found here (tested and it works well): https://stackoverflow.com/a/4869034/1121352
NOTE: do NOT use the openPreference() function to go back to parent PreferenceScreen, because after a few iterations you will get a stack overflow and your app will crash (because Android will keep in memory the history of all previous menus, including the ones you open via openPreference()!).