Android SeekBarPreference custom view - android

I'm trying to implement SeekBarPreference into my preference XML. I have attempted to use MrBIMC seekbar (https://github.com/MrBIMC/MaterialSeekBarPreference) which mostly worked but due to it being old, there were some issues I had to come up with ugly solutions for.
<SeekBarPreference
android:defaultValue="5"
android:dependency="a_different_preference"
android:key="seekbar_key"
android:max="40"
android:summary="Select your value"
android:title="Seekbar value"
app:iconSpaceReserved="false"
asp:min="1" />
The above code does mostly what I want, except I can't figure out how to add a measurement value.
sample:msbp_measurementUnit="km"
The above is what is used in the MrBIMC library to set a unit after the value, but can't achieve anything similar natively.
Lastly, in my preferences.xml, I get the error "Element SeekBarPreference is not allowed here" which is preventing the IDE from showing me any suggestions to get what I am after.
Edit:
Since asking this, I have learnt that the native seekbarpreference does not seem to have the ability to add a measurement unit after its value... So, how exactly can I create a custom view, that looks and behaves the same, but has the ability to input a measurement unit?

This Stack Overflow question I had found has used a SeekBarPreference as an example of how to make a custom Preference: Creating Custom Preference
In addition to this, in the XML file, you can just add a spinner to seekbar_preference.xml.
Or, an even easier solution (but not really what you want) is to add a separate ListPreference to your preferences.xml file and input the preferred unit of measurement from there.

Related

Any way to avoid "android:" statements in Android XML layout file?

Is there any way to avoid hundreds of "android:" statements in an Android XML layout file? I am new to Android and I find the "android:" statements make layouts very hard to read. Plus they are a pain to constantly type.
For example, instead of this:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
I would like to just see this:
layout_width="wrap_content"
layout_height="wrap_content"
layout_column="2"
If you're using Eclipse (and presumably Android Studio has similar functionality, but I've not used it) you can auto complete layout properties, e.g. if you type w then ctrl + space it will auto complete this to android:layout_width in most instances. You never really need to type the android: part.
I'm not aware of a way to remove the namespaces.
No. That is needed to know it is part of the Android framework. Instead of say a custom style or custom View. I've done a little bit of Android coding and it really isn't a big deal.
For example, there is a copy/paste feature which can make it go faster. Also, most IDEs have autocomplete which is very handy.

How to know what android:id Android expects?

In some android classes you can set a custom layout. As far as my understanding goes, these custom layouts need certain android:ids to work.
For example, for the ListActivity a ListView with #android:id/list has to be provided and this is specified in the documentation.
What about other views? For example, I was checking the API Demos and came across
<CheckBoxPreference
android:key="child_checkbox_preference"
android:dependency="parent_checkbox_preference"
android:layout="?android:attr/preferenceLayoutChild"
android:title="#string/title_child_preference"
android:summary="#string/summary_child_preference" />
There's a layout specified for the preference. That layout seems to be preference_child.xml, in which there's #+android:id/title and #+android:id/summary, which I assume the view will use to provide the title and the summary, but is this documented anywhere?
How do I know what resource IDs I have to use so that everything automagically works?
AFAIK, there's no trick to find out but to know the documentation or open the android's id.xml and look for references.
P.S.
Your code demonstrates how to use a specific attribute out of an entire style (the use of "?"), it has nothing to do with ID's

CheckedTextView Attributes ID and checkMark

Just start developing with android and think instead of reading a book a webinar could be better because a webinar could also teach me short ways and how an android developer thinks when writing the code but now got a problem
<CheckedTextView
android:id="#android:id/text1"
android:checkMark="?android:attr/listChoiseIndicatorMultiple"
</>
I dont understand the above code up to now see lots of different id definitions some of them was for resources and start with #resource/name, and some of those id definitions was like #+id/name just for creating a new id for the component but this time it is using android:id/text1 and I dont understand why it is using it in that manner
Besides, the checkMark thing make me confuse more what are all those ?android:attr/listChoiseIndicatorMultiple means?
Could you please explain me and show me some resource where can I find all those magic attributes so I can cope next time by myself and hope someday can answer other newbie questions
Thanks a lot in advance, and all comment will be appreciated.
Well, reading the docs has always been helpful to me:
Android Developer Site
XML Layout specific docs
#android:id/text1 is just a format used when the id has been previously defined. When you put a + in there that means the framework should create the resource id if it doesn't already exist.
It's normal to use #+id/thisid when defining a new view in a layout, and then use #id/thisid to reference the aforementioned view from another part of the layout (say, in a RelativeLayout where you need to tell one widget to be below another).
A question mark before the ID indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute.
#android:id/text1 basically this is used when you create any android component like button, layout, textviews etc.
but when you need any external component which is general for different platform like any color, image etc then you can declare it as #resource/name.
actually there is nothing different just keep one thing in mind that in #android:id/text1, id will simply work as an class name will contains other objects like textview, imageview or any other.
now if you declare #resource/name then in that also instead of id class name will be resource. actually when you will use it in java then these(#android:id/text1) will be converted into object hierarchy.

Android - Is it possible to change a property specifically for each ListPreference entry?

I have an ordinary Android ListPreference defined in my code -
<ListPreference
android:title="Font"
android:summary="Choose the font of the reader"
android:key="fontList"
android:entries="#array/fonts"
android:entryValues="#array/fontValues">
</ListPreference>
It gives a list of a couple of different font types that the user can pick from, nothing special. What I wondering is, is there a way to set each list item's font to the font that it displays? This would be a nice feature as it would allow the user to see what they have to pick from before having to test it out.
I can't see any obvious way of doing it, or at least a way that wouldn't destroy the nice default UI.
Any help would be appreciated.
The best way to do it would be to extend the ListPreference class and implement your own preference. From memory I think you need to override the onCreateDialogView, onBindDialogView, onSetInitialValue and onDialogClosed methods. Best place to look is at the List Preference page on developer.android.com
like he said for fonts u will need custom one. But what I found that there are alot of different default android:theme="#android:style/Theme....."
try the once that are available ... there are 9-10 of them.
maybe u will get somewhat closer to what u need that extending your own custom UI.

ListPreference - Custom items possible?

I'm trying to add an image / icon to certain entries of a ListPreference alongside the text.
I would like achieve this programmatically.
Here's an excerpt of the preferences.xml
<ListPreference
android:key="prefGameMode"
android:title="#string/pref_game_mode"
android:summary="#string/pref_game_mode_desc"
android:defaultValue="fourChallenge"
android:entries="#array/arrGameMode"
android:entryValues="#array/arrGameModeValues"
android:negativeButtonText="#string/cancel" />
...
The goal here is to illustrate that some of the options listed are unavailable/ locked in the current version of the app. However, the code-base is used as a library, so I would like the solution to work via code, rather than xml.
Any ideas how to do this? Thanks.
Preferences already gives you a way to indicate that an option is unavailable: just set enabled properly.

Categories

Resources