How to add picker to insert amount? - android

i need to add a picker in my activity that allows to insert a double value, with minimum 0,2 and step 0,01. Something like this:
I tried to search on Android documentation and i found these:
Is it possible to suit Android picker to my purpose? Does exist anything better?

This post might be of help:
Getting float/double from NumberPicker
Although I think the best route is to just use a Spinner, see this post:
Strange double-to-string conversion

Related

Is it possible to switch the format of date picker header?

I am trying to change the header on material design date picker as you select a date to a different format than default. Current default is Month , year : ex: june 22, 2021, but I want it such that its Mon, June 22. It's shown on material design document as the first design, but there's no indication of how to go about changing this format?
Any ideas?
material designs : https://material.io/components/date-pickers
what I want to achieve is this :
Unfortunately, you can NOT change Date Format and Local of MaterialDatePicker.
Since MaterialDatePicker is very restricting, so as many other Material Design Components, I recommend you to use an alternate Date Picker Library such as MaterialDateTimePicker.
It basically fulfills all your needs:
Change date format: setLocale(Locale locale) ✅
Choose from multiple date UIs ✅
Very flexiable and easily customizlbe to fit your needs ✅
PS: There is one more popular alternative: android-betterpickers
Let me know if you have any other questions.
After looking into the source, and trying some things, I did find a solution. Unfortunately, it's not that simple to implement and I guess switching to MaterialDateTimePicker is still the best solution here.
The conversion from date to text for the header is done by the DateSelector via getSelectionDisplayString(Context context). See getHeaderText() inside of MaterialDatePicker here.
Sadly, MaterialDatePicker is final, so you can not simply create your own and override this method. But, with the given Builder, you can use MaterialDatePicker.Builder.customDatePicker(DateSelector selector) to place your own DateSelector (source).
Material uses their SingleDateSelector (source) for a simple date selection. But again, it's not possible to build upon this selector and write a custom getSelectionDisplayString method, because the class is restricted. Knowing this, it's needed to write your own DateSelector.
Building your own DateSelector is a bigger task on its own. It may be possible to copy from SingleDateSelector, but it's using some private classes and methods you need to copy, too.
To cut a long story short, I guess this is too much for "simply" changing the date format.

Android: advanced ColorPickerDialog

I'm looking for an advanced Android color picker dialog. The standard color picker from the API Demos and examples from this post aren't quite acceptable to me. I'd like it to look like this: this image. Are there any open source color pickers that look like that?
UPDATE: My primary goal is to make the Color Picker easy to use: it'd be great if the user only needs to click once to pick any color, and all possible colors are represented. The Color Pickers from the examples I've mentioned require two clicks to pick a color and are too complicated for the average user.
This one looks pretty close to what you want, and is FOSS:
https://github.com/LarsWerkman/HoloColorPicker
how about this solution ?
look at the screenshot:
source code here .
Have you tried Android Color Picker?
If you need to show the RGB-Code of the currently selected color, just modify the dialog by adding an TextView and adding an update to it in the ColorChangeListener (or whatever it's called)
Or take a look at the color-picker dialog of CyanogenMod
Here a link to the source: CyanogenMod color-picker on GitHub

Auto Increment(+) and Decrement(-) button like time picker

Hello I'm trying to get an edit increment decrement, to no avail.
I see on Time/Date palette: Time picker, but i want only one box.
I'd like an edit like this:
Thank You!
You can use NumberPicker class. But it is available from SDK v-11. To use in projects that are aimed at SDK versions less 11, you should implement your own class. But you can use AOSP's NumberPicker class as template. Also, but I'm not sure (because I've never tried it) you can use SupportPackage.

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.

Customize the digital clock

I am using the digital clock but i need a simple customisation to it. My code is like this.
DigitalClock digitalClock=new DigitalClock(this);
//Set of attributes
digitalClock.setDrawingCacheEnabled(true);
setContentView(digitalClock);
It displays the time in hr:min:sec format. I want it to look like hr:min format and also I want it in 24hour format.
I am suspecting that I should use the calendar apis and use string format api. But I am not sure with the best approach.
Any suggestion is precious.
Thanks
Time format is hard-coded, so you can't change it. The only way to change it is to re-implement DigitalClock widget. Yo can get source code from here.

Categories

Resources