I'm new to android dev and I like to make a 3 states checkbox for my app. How is that possible ?
It should allow the user to switch between checked/unchecked/misc states.
I'm a bit lost. Should I subclasses CompoundButton and modify the state-list drawable ? I'm actually stuck at subclassing.
I was once looking for the same thing and found this. I ended up changing my requirements so cannot speak to its effectiveness, but looks like they implement the entire thing as Button, see ThreeStateButton and ThreeStateCheckBox.
Related
I want to use checkbox in RemoteViews but it does not support Checkbox object, so I think that I can achieve a similar effect using Button with custom state-list drawables. Basically I want an on/off switch which toggles on click and looks like a Checkbox.
I believe I am not the only one having this requirement so maybe someone has already made this checkbox-like button before. Please share with me the xml or point me in a direction. I don't have 100% understanding of drawables but I can find a way through it if I am heading in the right direction.
One shortcut I could take is to use an ImageButton and then alternate the images of checked/unchecked states programmatically, but I think inherent state changes would be faster.
I think all custom button tutorials I have been able to find for Android assume you are using three images for your button: a normal image, a pressed image, and a focused image.
Instead of essentially tripling the size of a given button's resources (and creating more work for the artist/UX guy), is it possible to only supply a normal button image, and for the other states, draw some sort of overlay over the existing button by extending the Button class?
Has anybody tried doing this with any success, or is it just accepted that all custom buttons need an image for each state and that is that?
You could by overriding the draw methods of the view in your custom button but it would be a simple process as you would have to also identify the different states yourself.
I think the correct answer to this question is essentially what #Luksprog said in the comments... It simply isn't worth it. Just make the extra art.
On Android, I need a checkbox (or checkbox-like component) which can represent/control a flag for a number of selected items. There are 3 possibilities which I need to represent:
Flag is set for all items.
Flag is set for none of the items.
Flag is set for some of the items.
I'm imagining something like this:
If the user selects the checkbox when it's in state 3, it will switch to state 1. Thereafter, it will only toggle between states 1 & 2.
If you're familiar with the checkboxes in the attributes section of the file properties dialog in Windows, that's what I'm after.
Is there a native Android UI widget, or an existing open-source widget, which can do this?
I'm fairly confident I could do my own implementation, but I'd rather not re-invent the wheel!
I think you'd be best of with your own implementation. And it will be a fairly simple one, just use the: setOnCheckedChangeListener, here is a simple tutorial that just shows the use of this listeners, you will just implement changing your flags, and setting some of your checkboxes checkable when in the correct state.
http://developer.android.com/guide/topics/ui/controls/checkbox.html
hope it helps!
At the top there is the favorites/styles/all channels
i don't know what that widget/control is i need to know what it is
i am certain i saw it before i just can't seem to find it again.
then there is a listview which is easy to implement no help needed there
then the same control again, i need to know how to build it.
it looks like a native Android control, i know how i can make one just like it using image buttons but i am sure i am missing something.
P.S. this is an image from sky.fm app on android
EDIT: I Do no need help with the ListView i already did that
What i do need help with is how to make the "favorites/styles/all channels" buttons if there is a way to do natively.
If there isn't a way to do natively, and you are sure just say there isn't a way to do natively ( that would be a good answer )
the perfect answer would be a working code, but i am not lazy i am already implementing the code my self
There's no native control for this. It's probably a Button or maybe ToggleButton. You could create a background xml with different states for selected true or false. And when you click the button toggle the selected state.
Top might be a custom tab layout, or just a bunch of buttons with custom styling.
Main part looks like a listview with complex row views.
Bottom almost definately is a bunch of buttons.
You can implement it using ClickableListAdapter.There is also tab implementation.try it.
Just make it using image buttons and put filters in your ListView, or create your own filter form scratch !
I have an app widget which runs neatly. However, I am unable to highlight a click on a linked item. I've seen it in the standard app widgets like 'Music' and 'Power Control', for instance. Moreover, I've also been studying the Music app widget's source at album_appwidget.xml. The only thing I could think of is the LinearLayout defined at lines 23-35 which states
android:clickable="true"
Unfortunately, this does not work for me. So does anyone have a hint on how to highlight a click on an app widget? I've tried the LinearLayout, TextView and Button. None of them displayed a border as a highlight.
Thanks in advance,
Steff
you need to create images for those states like focussed state, pressed etc like in a button and define them in your background.
Try looking at the custom buttons where its explained how to accomplish the task thats similar to your needs.
http://www.gersic.com/blog.php?id=56.
if you want to look more and add more states you may ge better idea if you look at the android source code for buttons where they have images for each state of the button and every other widget.