I have an android Dialog with a 3 numberpickers inside. Changing the 3rd picker triggers a change in the displayed values of the first 2 pickers. However I've noticed when I change the displayed values, and call
setWrapSelectorWheel(false)
it still shows the new values as wrapped visually (I can see the last value above the first one).
If I touch the picker it suddenly snaps into non wrap selector wheel. What's odd is I call
getWrapSelectoWheel()
after setting the displayed values and it returns false... just like I set it. But visually it's wrong.
Any ideas what's going on?
Many thanks!
I found a solution, Daniel was on the right track, however it appears that initializeSelectorWheelIndices is actually a bad thing once you've already set your values. Because of this, you need to call setMinValue and setMaxValue BEFORE you set your values. However, if you already have an array set on your picker, if you call setMaxValue with a higher value than the current array, it will give you a ArrayIndexOutOfBounds exception.
The solution then is to clear the old display values, set your max value, then you can call setWrapSelectorWheel and setDisplayValues:
public void updatePickerValues(String[] newValues){
picker.setDisplayedValues(null);
picker.setMinValue(0);
picker.setMaxValue(newValues.length -1);
picker.setWrapSelectorWheel(false);
picker.setDisplayedValues(newValues);
}
I don't know what version of Android you're running but I would suggest you read the source code for the NumberPicker (v4.2.2). Perhaps you need to trigger a call to the private method initializeSelectorWheelIndices which can be done via a call to some of the public methods.
Although I do think your usage of the picker, by changing the wrapping flag part way through, does seem a little unusual. Don't you want this behaviour to be consistent? In which case make a call to setWrapSelectorWheel once after you've set your min and max values and then leave it alone.
I've verified this behavior as well on kitkat. It's a bug. Couldn't find an existing report so I created a new one here: bug# 98319
Per previous answers I found that making setWrapSelectorWheel(false) the last call after all setup calls will work for most scenarios. In my case I'm dynamically changing limits of the NumberPicker as the user is interacting and I just can't get it to behave 100%. I'm opting to live with the wrap selector.
Related
Simplifying, I have this structure
Form {
tab=Container(BoxLayout.y());
other stuff
}
The Form is not scrollable (and it is not supposed to be), tab is.
At some point I want to redraw the Form to keep it up to date with some new info added, and I do that creating a new one and showing it.
But I want to scroll down the Container tab to its predecessor's Y-coordinate.
I can easily save the Y coordinate in a static variable using
scrolledToY=tab.getScrollY();
But I can't find a way to set it back when I create the new form.
setScrollY seems to be protected, and indeed if I try to run the program using it, I get an error
error: setScrollY(int) has protected access in Component
tab.setScrollY(scrolledToY);
What is the correct function to use, instead?
Thanks.
You can use scrollRectToVisible().
FYI you can just modify the container and call revalidate to update the UI. This will prevent a nasty refresh problem you might experience. Also check out InfiniteContainer which might be what you're really looking for.
My idea is to create a kind of growing form. Now the question is: What is the best way to do this? I haven't found a library, yet. On the picture below, you can see how I thought it to be. It should go to the next step after each input and an EditText field should appear. Any advice on existing libraries or tips on which UI component should be used to realized would be appreciated. Thanks for the help!
you have plenty approach but the one i prefer to use:
make your list, then for each index assign its next EditText. by default make your all EditTexts (except first one) disabled. then add a listener each index to observe its text. as soon as it was filled tell that listener to enable its next EditText.
maybe its not so efficient but its simple and makes code more readable. and also you can extend that easily if you just implement two first indexes because the rest is just the same.
I get the dialog for changing the properties of the print job by invoking the PrinterJob's printDialog() method without any parameter. There is a field where the user can change the the number of copies to be printed on the right-bottom of this dialog.
And now I want to disable this field (the spinner). That is only one copy to be printed and the user can't change it.
Are there any ideas for it
I don't think there is any way (or i am not aware of) to modify the native or the cross-platform Java print dialogs (last one might help you a bit). What you could do is maybe display your own dialog (without a spinner field) and under-the-hood do whatever you want (like PrinterJob.setCopies(1)).
More info i found here.
Also, have a look at the Java tutorial on PrinterJobs.
With a method like glColor4f(0f, 0f, 0f, 0f);, it sets the values to whatever parameters one puts in. However, what I would like to do is only slightly change a color. Is there any existing OpenGL method that will add or subtract its parameters to the existing colors it has?
The only other way of doing this that I can come up with is first getting its color values, then editing those how I want to, and finally sending them back with glColor4f().
So, in closing, I would like to know if there is either a method for editing existing RGBA, or at least retrieving an existing RGBA.
Well, you can get the last value set with glColor4f by using glGet with GL_CURRENT_COLOR, but I wouldn't recommend it; glGet operations are generally bad for your performance, so try not to do it too often.
A better idea would be to maintain a local copy of the last value you sent to glColor4f, so that you have the data client-side instead of having to request it from the opengl driver.
There's no way to add or subtract from the current color that I'm aware of.
Edit: Actually I just looked up and see this function called glSecondaryColor which may do what you want. You can supply a second RBG color, and then enable GL_COLOR_SUM, and the two colors get added together.
I have a custom component based on the JSlider. It's essentially the same thing only it has 2 thumbs, which I named a DualSlider.
I need to change the maximum value of the slider once in a while, so every time I do, I call updateUI to reflect this.
public void updateUI() {
this.setUI(new DualSliderUI(this));
this.updateLabelUIs();
}
However, the maximum value of the DualSlider when I try to use it is still set at the original value no matter how many times I try to change it while using my program. I can confirm with a few println statements that a new DualSliderUI is being made with the slider that has the new max value, but for whatever reason the original DualSliderUI I initialized the slider with is the one that is in use.
What other things do I have to make sure I do when I update a property so I can avoid this?
1) I can't see reason for usage updateUI() this should be done once time, only when you built this JSlider, never do that repeately
2) you have look at BoundedRangeModel, maybe