After long struggle i am posting this question with hope where i will get answer to my question.
I can't able to create custom preferences activity with background image, view bars between every preference,.
As i had designed one custom preferences page but i cant able to make preference cell as button and i cant able to add key values to preferences to make them as sharedpreferences, even i tried with preferencesfragment also, but i couldn't able to make it work.
Please help me from this custom preferences activity.
Related
I have a very simple question about loading layout in main activity. I have a simple layout defined in activity_main.xml which is loaded in MainActivity's OnCreate() using
setContentView(R.layout.activity_main).
Then on a button click, I add another view item (button) which shows up correctly.
But when the app is closed and opened again, I need to retain what was added last time when the app closed. How do I do that?
I searched some questions here, but most of them talk about saving values using SharedPreferences or saving state, but it is not clear if the layout can be saved as well.
Thanks in advance.
I think the best solution is saving latest state values by using SharedPreferences, because it is a good way to save any simple data for long term.
Saving state via using saveInstanceState is a short term solution and if you close your app completely, saved instance will be gone forever.
Possible solution:
First, you cannot save a layout as you think, but you can get the layout's parameters and other features as variables, then you can save these by using SharedPreferences.
Secondly, you should check if there is any saved layout states when you start the activity. If any, you can use the pre-saved parameters for adding your layout dynamically/programmatically.
i am new to custom PreferencesActivity, i am working since three days to get custom preferences, what i want is i want a preferences screen with background image and color views for every preference cell,
1) i had tried with res/xml/preferences.xml, but i cant create background image i had tried with many solutions but i couldn't find any solution.
2)i had tried with res/layout/pref.xml, but i couldn't able to save the settings of preferences
please help me in creating such type of preferencesActivity with background image
see How set background drawable programmatically in Android
and save this link http://developer.android.com/reference/android/content/SharedPreferences.html
I have a collection of items which are shown using a ListView.
Each of these items has its own settings. By clicking on one item I want to allow the user to view/change its settings.
What is the best way to do this?
It would be nice if I could use something like PreferenceActivity as this provides a nice layout. Unfortunately the preference mechanism always saves the chosen preferences to a global file (see SharedPreferences).
A workaround might be using multiple files, one per item, but I don't like this solution since the collection is dynamic and I prefer the settings to be local to my objects.
Another workaround might be opening a PreferenceActivity, then reading all the settings and saving them to the appropriate object. This also seems far from elegant.
Finally, I could implement my own activity with a ListView and custom item layouts, but this seems a duplicated work to get the same behavior and style.
Any suggestion is welcome :)
Thank you
I'd do something along the lines of PreferenceActivity, but save the preferences to the items themselves or something associated with them. To display the preferences input, use a dialog Fragment. You can then either pop up the dialog, or display it as a regular Fragment.
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
I have a preferences.xml, containing various settings for my app - their possible values\names, defaults, etc.
It was previously used simply in a PreferenceActivity with addPreferencesFromResource().
Now I am creating a completely customized settings UI, and I want it to have nothing to do with PreferenceActivity.
All I ever want is to have my preference hierarchy from the XML (as PreferenceScreen), so I can use it to construct my own UI.
I don't want Android's list adapter, I don't want the dialogs, etc. Only the data model.
Sadly, I haven't found a nice way to do that.
The only close thing I can think of is extending PreferenceActivity, providing a custom "R.id.list", and setting its visibility to GONE, so no one will see Android's preference UI.
Any good, clean way to accomplish that?
You can accomplish this by using the PreferenceManager directly. First you would call the setDefaultValues which does the loading of your preferences XML resource. Next you can get access to the SharedPreferences by calling getDefaultSharedPreferences and perform any preference changes through the SharedPreferences object. To edit your preferences you will need to get the Editor from your SharedPreferences object. Make sure to call commit on the editor to actually save the changes you have made.