How to navigate back through Android preferences programmaticaly? - android

I have several preference screens. When user click on preference named log-of - I have to disable and hide some preference screens. Because of disabled preferences I need to go one level up in screen preferences hierarchy.
Looking for valuable suggestion.
Thanks.

I decomposed preference hierarhy.
Now have 3 different xml layouts for each preference screen.
When user click 'logof' - I make change in app data and call finish activity. This returns me one level up :) This way causes more code, but logic is clear now.

Related

Preference Fragment doesn't open in new Preference screen

I've been trying to show preference fragment data in a separate preference screen. Tried alot of things but no success. Currently, the data is being displayed on the right half of the screen, while header preferences are visible on the left side:
I want to show the data on full screen:
Thanks in advance!
This guide explains the way to implement what you want.
Basically, you should only have a single PreferenceFragment per PreferenceActivity screen (this toggles a single-pane view); create & call another PreferenceActivity when you want to show another group of preferences.

Opening Fragment From Inside PreferenceScreen

sorry if this is a stupid question.
So, I've got a settings.xml defining my preferences, and at some point in the tree I have:
<PreferenceScreen [...] android:fragment="path.to.fragment" [...] />
And when I tap that thing, I go to my fragment.
That's working.
My fragment is a ListFragment, because I am showing a list of Bluetooth devices on this screen and can't just declare them statically.
My question is, when a user clicks one of the list items in my ListFragment, I want to open a details screen where they can set a preference with that selected device, but I can't figure out how to programatically create and launch this next fragment while still keeping things in the nice tree the preferences provides.
For now I'm just creating an activity so that I can move past that part of the issue, but I have to figure something out before this is done.
Is there an easy way to do this, or am I taking the wrong approach entirely?
Thanks!
EDIT: Picture
So, Page 1 is my settings fragment, which is built using the XML with the highlighted option being generated using PreferenceScreen as above.
Page 2 is my listFragment, and because those items come from Bluetooth, it can't just be another settings xml entry.
Page 3 is what I get when I pick an option (WIP). To get to this point I had to make it an activity and use startActivity, but the other two were fragments. I'm asking if there's a way to programmatically do the same thing the PreferenceScreen option is doing in the xml and launch a fragment with the top bar maintained and stuff.
Alright, here's what I've got.
I realized that at the top level I had a PreferenceActivity, and it has the method startPreferenceFragment.
So, I do:
((PreferenceActivity) getActivity()).startPreferenceFragment(new MyFragment(), true);
Which works for me.
It doesn't feel like a solid solution, but it has the effect I want and I have to move on.

Where to put preference based layout operations in ActionBarActivity

In my app I am creating a custom preference screen. This screen in reached via mainActivity (launcher). The mainActivity also shows the current status of some of these settings by reading them and laying them on views. Now, when the user will reach one of the preference screens and edit them, by design I aim to bring him back to the mainActivity (it would be intuitive to press the back button). This time however I want to show the latest edited settings.
I am used to putting layout operations in onCreate. But, in this case onCreate will only be called once when the activity starts and read the status of preference settings and lay them on screen. However, when he will open a settings activity, edit them and press back button he will not see his latest settings laid on screen as onCreate need not be called.
So, on what activity callback should I place the operations to read preferences and lay them on views.
This is based on my understanding and I may have messed up big time. Guide me, Thanks...
To anyone looking for an answer. Its pretty basic stuff. Create function in your main activity to read preferences and update your views. Now, start your preference activity using startActivityforResult() and when result arrives from that activity, run the same function inside onActivityResult(). Done.

Preference with in-line options

I've created a PReference Screen which lets the user manage a series of elements marked by himself as "favorites". I create a Preference category then fill it up with options dynamically, taking them from a sqlite database. This is a screencap:
And this is a screen mockup of what I want to achieve:
That is, I want for every preference item to add an in-line remove option that allows users to directly remove favorites.
The problem is I don't know how to do this, and I've seen no similar examples. Is it even possible?
Android provides an easy means to implement preferences screen, but standard android ListPreference does not provide an easy way to display an image for each item if the list. To add the images to the Android ListPreference, we need to use a custom xml attribute
Here is some example that may help you
http://www.cmwmobile.com/index.php?option=com_content&view=article&id=4&Itemid=12
How to add icons to Preference
To delete prefrence from prefrence screen you you can refer this Link : How to determine which preference item from custom layout button click

Confirm and discard button in the android preferences activity

I'm working on the preference activity. The matter is about the possibility of add a button that allow to confirm, and eventually (that would be nice) a discard button in order to discard the changes applied at the preferences.
Let me explain better.
As far as I've seen it is possible using the common techniques that i've found in the tutorial to set different preferences using checkboxes and so on. The normal use case that involve preferences require that the user performs selections and after that click the BACK button in order to return to the old view.
However in the usability test i've done, it seems that this step is not always straightforward for all the users, and moreover a lot of them are not sure about the fact that the changes on the preferences are comfirmed.
Now we arrive at the question. is it possible somehow to have in the preference view selections (in particular one just composed by a group of checkboxes) to have an OK and eventually CANCEL button?
You have 4 options:
1) Design a layout and use a normal activity similar to the preferences screen where you give the user 2 buttons: Save and Discard.
2) Add a menu to the preferences activity with save/discard (and of course you will have to save the previous state and revert back to it if the user decided to discard).
3) Handle back button press on the preference activity where you popup a dialog asking if they want to save the changes
4) Add 2 "actions" to the preferences where 1 is save and 1 is discard and each goes to its own activity... Complicated and ugly in my opinion...
On a side note, I really believe users are familiar with Android's UI as 99% of the apps using preferences don't have this save button so it should be straightforward to the users that when they click on a checkbox - it is saved.

Categories

Resources