Partially selected checkbox on Android? - android

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!

Related

how to mimic android checkbox using button and state drawables

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.

Best control to be used as dropdown list in android

I have an activity which one of its components is a EditText. The goal of it is the following: when user clicks/taps on it, another activity is called to select some items (categories). I have implemented it using an activity that extends listactivity and using a custom adapter to paint custom rows for items.
All is ok, but I guess if using a EditText is the best option. The problem using this kind of control is that when user clicks/taps on it, the virtual keyboard appears and I do not want it to appear. If I use a TextView instead, virtual keyboard does not appear, but it is not clear for user that he have to click/tap on it to select a category (as the underscore line is not shown here as when using EditText).
So what android widget is the best to use in this scenario?
You can always use expandable list view there are many examples online that could help u to create it much more flexible than a spinner and it looks elegant and easy to use, it also show the user directly what is used for by just giving it a look and u can always customize it and play with its look and functionality.
Sounds like you are looking for a Spinner? That way you wouldn't have to load up a separate Activity to make the category selection. Otherwise, why not just use a Button? It's obviously clickable, that's for sure!

Android: how to create per-item settings activity?

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.

Subclassing CompoundButton to create a three states checkbox

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.

Recommendations for a 'permanent' Selector in ListView

I'm looking for suggestions on how to go about adding a ListView selector that is 'permanent'. By this, I mean a single row in the ListView is always highlighted; it should move up or down in reponse to any D-pad presses (i.e. like the default selector) but also remain set/highlighted if the user were to scroll the ListView in either direction (i.e. it's still highlighted even when it's off-screen).
I've looked at using the standard selector mechanism, but am unable to get the selector to remain in place if the ListView is touched (and thus scrolled), so it makes me think that this isn't the best option? Perhaps there's a <selector> "state_*" that I've ignored?
The other option would be to use the onItemSelected() callback, but at first look this appears more convoluted?
Any suggestions/recommendations/experiences gratefully receieved.
Cheers
James
I'm looking for suggestions on how to go about adding a ListView selector that is 'permanent'.
Please do not do this. There is no selection in touch mode, and that is by design. As suggested in this article, "Use the appropriate feature if you need persistent selection (radio button, check box, the ListView choice mode, etc.). Do not try to keep the focus or selection in touch mode."

Categories

Resources