Toggle button with more states that two

by Duskox » Fri, 11 Mar 2011 01:51:50 GMT


Sponsored Links
 I am trying to find if there is a possibility to use togglebutton in
such a way to have more states that two? So I want a single button to
change appearance (background image) depending on what state it is in.
So if I have states 1, 2, 3, 4, 5 and off to be able to change between
all those states and display a new image for every state.

Thanks!
D.

-- 



Re: Toggle button with more states that two

by Justin Anderson » Fri, 11 Mar 2011 02:01:08 GMT


 I don't think so, but it shouldn't be too hard to just subclass the Button
class and implement this behavior yourself.

Thanks,
Justin Anderson
MagouyaWare Developer
 http://sites.google.com/site/magouyaware 






-- 


Sponsored Links


Re: Toggle button with more states that two

by mort » Fri, 11 Mar 2011 14:58:18 GMT


 I think this would also break the user experience. Better use a
spinner. You can show different "foreground" images if you use proper
layouts and adapter.
For both button and spinner you could simply set a new button
background when the item has changed, i.e. in the OnClick- or
OnItemSelectedListener.
However, I don't think background images (at least if they still
should look like common button surfaces) are quite intuitive, esp. not
with so many states.
Depending on your screen layout, it might also be a good idea to
simply show an icon and/or text with prev./next state arrow buttons or
tabs. I for one wouldn't like to press a button 5 times to get to the
previous state again...

-- 



Re: Toggle button with more states that two

by Duskox » Mon, 14 Mar 2011 21:54:24 GMT


 Thanks for your suggestions. What I want to do is a button that will
have an off state and then a repeat all state and repeat single state.
Like in any mp3 player where you can loop the whole playlist, single
song or no loop.

I'll check spinner out and then if that is not what I want go to
create a subclass.

Thanks,
D.

-- 



Other Threads

1. Problem with listening to a PhoneStateListener in a service



If you get a "Force Close", look at the Java stack trace to tell you
where your code is failing. You can get at the stack trace via adb
logcat, DDMS, or the DDMS perspective in Eclipse.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 2.8
Available!

-- 

2. Async thread aborted after catching (all?) exceptions

Yeah, my bad..

11-11 21:47:01.811: INFO/InetAddress(797): Unknown host
thishostdoesntexist.net, throwing UnknownHostException
11-11 21:47:02.270: ERROR/AndroidRuntime(797): Uncaught handler:
thread AsyncTask #1 exiting due to uncaught exception
11-11 21:47:02.260: WARN/dalvikvm(797): threadid=15: thread exiting
with uncaught exception (group=0x4001aa28)
11-11 21:47:02.270: ERROR/AndroidRuntime(797): Uncaught handler:
thread AsyncTask #1 exiting due to uncaught exception
11-11 21:47:02.280: ERROR/AndroidRuntime(797):
java.lang.RuntimeException: An error occured while executing
doInBackground()
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
android.os.AsyncTask$3.done(AsyncTask.java:200)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:
234)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:258)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
java.util.concurrent.FutureTask.run(FutureTask.java:122)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:648)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:673)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
java.lang.Thread.run(Thread.java:1060)
11-11 21:47:02.280: ERROR/AndroidRuntime(797): Caused by:
java.lang.RuntimeException: Can't create handler inside thread that
has not called Looper.prepare()
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
android.os.Handler.<init>(Handler.java:121)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
android.widget.Toast.<init>(Toast.java:68)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
android.widget.Toast.makeText(Toast.java:231)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
foo.bar.MainActivity.onTaskError(MainActivity.java:113)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
foo.bar.MainActivity.access$2(MainActivity.java:110)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
foo.bar.MainActivity$GenerateMangaTitles.doInBackground
(MainActivity.java:223)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
foo.bar.MainActivity$GenerateMangaTitles.doInBackground
(MainActivity.java:1)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
android.os.AsyncTask$2.call(AsyncTask.java:185)
11-11 21:47:02.280: ERROR/AndroidRuntime(797):     at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256)







-- 

3. Problem with listening to a PhoneStateListener in a service

4. Async thread aborted after catching (all?) exceptions

5. how to remove completely the SDK and ADB

6. Title bar keeps popping up on AlertDialog presentations despite disabling it in the activity

7. title bar keeps popping up despite disabling it in the activity