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. phone 2 phone game

I'm just getting interested in doing some Android development.  But I
tripped at the first hurdle.  I'm used to doing nio socket comms in
Java, and would like to do something similar between 2 phones for a
simple game.  I have a few requirements and not sure which API(s)
would work best, or are suitable for what I'm trying to do?

1.  I want the app to run in the background and auto-detect when
another player(phone running same app) comes into range.  BT? Wifi?
Common server roundtripping with GPS location (yuk!) Something else I
haven't thought of?

2.  Once two phones have discovered each other, I want to start a TCP
socket to socket comms session between the devices (it's fine, if not
better, if the user has to confirm this connecion).  ie 1 device will
assume server role, and the other will be a connecting client.
Possible? Supported?

Any tips or pointers would be really appreciated.  So far I'm only
finding info relating to GTalk or XMPP (deprecated?).

--~--~---------~--~----~------------~-------~--~----~

2. Noobie problem with creating Classes which use other Classes

I want to create the following:
a main activity Class which creates/uses a Class which has several
fields, each of which has two pieces of data, a String "value" and a
Boolean "visible" (describing whether that piece of data will be
visible to other users). I have done this by creating a subClass which
basically is a "record" containing two fields.

But the following code fails. It fails whenever I try to assign a
value to the "value" field or the "visibility" field. (It fails with
either direct assignment or with creating a setter method -not
shown.).  The error code indicates a null pointer exception is thrown
when I try to make the assignment, but I do not know why this should
be the case, or how to fix it.... (BTW if I don't use the extra
subClass containing two pieces of data, and just use a String type in
the primary Class, it works fine, but that's not what I was hoping to
do...)

(Oh, I am still using 0.9, but I don't think this is related to
that...)

Any help would be greatly appreciated, Thanks, Jim.


CODE:
import com.northwestradiology.com.Person1.StrRecord;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;

public class ResourceQuestion extends ListActivity  {

        public class Person2 {

                public class StrRecord {
                        String value;
                        Boolean visible;
                }

                public StrRecord Id;

                public Person2(Context ctx) {
                        super();
                        Log.v("person construct", "before Id.value= hola...");
                        Id.value = "hola";
                        Log.v("person construct", "after Id.value= hola...");

                }
        }

        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                Log.v("onCreate", "entering on create");
                Person2 me = new Person2(this);
                Log.v("onCreate", "after person2 is constructed");
//              Log.v("onCreate", "after person1 is constructed");
//              me.Id = "hola";
//              Log.v("onCreate", "after me.Id.value set to hola");

    }
}


LogCat:
09-26 23:10:33.678: VERBOSE/onCreate(2937): entering on create
09-26 23:10:33.678: VERBOSE/person construct(2937): before Id.value=
hola...
09-26 23:10:33.688: DEBUG/AndroidRuntime(2937): Shutting down VM
09-26 23:10:33.688: WARN/dalvikvm(2937): threadid=3: thread exiting
with uncaught exception (group=0x40010e28)
09-26 23:10:33.688: ERROR/AndroidRuntime(2937): Uncaught handler:
thread main exiting due to uncaught exception
09-26 23:10:33.708: ERROR/AndroidRuntime(2937):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.northwestradiology.com/
com.northwestradiology.com.ResourceQuestion}:
java.lang.NullPointerException
09-26 23:10:33.708: ERROR/AndroidRuntime(2937):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2131)

etc...
--~--~---------~--~----~------------~-------~--~----~

3. Announcement: Companies that announce Android support

4. How get incoming call phone number in sdk 1.0

5. Android and Visa

6. HttpURLConnection Bug

7. Is it possible to have a background listener listen to something being pluged into the USB port?