How to create toggle buttons that are "jointed"

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to create toggle buttons that are "jointed"

Postby fhucho » Mon Jun 22, 2009 10:00 am

Hi,
I want to show 3 toggle buttons in my app that would be "jointed" - like the Map/Satellite/List buttons on this iPhone picture: Image
How can I do that?
Thanks in advance!
fhucho
Freshman
Freshman
 
Posts: 8
Joined: Mon Jun 22, 2009 9:48 am

Top

Postby nbadal » Mon Jun 22, 2009 6:35 pm

The way I would do it would be to put three ToggleButtons, then in the OnClick() method for each put a setChecked(false) call for the other two and then put what ever changes to the application after that.

Example:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.     public void onCreate(Bundle savedInstanceState) {
  4.  
  5.         super.onCreate(savedInstanceState);
  6.  
  7.         setContentView(R.layout.togglelayout);
  8.  
  9.        
  10.  
  11.         ToggleButton b1 = (ToggleButton) findViewById(R.id.toggle1);
  12.  
  13.         ToggleButton b2 = (ToggleButton) findViewById(R.id.toggle2);
  14.  
  15.         ToggleButton b3 = (ToggleButton) findViewById(R.id.toggle3);
  16.  
  17.        
  18.  
  19.         b1.setOnClickListener(new View.OnClickListener() {
  20.  
  21.                
  22.  
  23.                 public void onClick(View v) {
  24.  
  25.                         this.setChecked(true);
  26.  
  27.                         b2.setChecked(false);
  28.  
  29.                         b3.setChecked(false);
  30.  
  31.  
  32.  
  33.                         /* The Rest Goes Here */
  34.  
  35.                 }
  36.  
  37.         });
  38.  
  39.  
  40.  
  41.         b2.setOnClickListener(new View.OnClickListener() {
  42.  
  43.                
  44.  
  45.                 public void onClick(View v) {
  46.  
  47.                         this.setChecked(true);
  48.  
  49.                         b1.setChecked(false);
  50.  
  51.                         b3.setChecked(false);
  52.  
  53.  
  54.  
  55.                         /* The Rest Goes Here */
  56.  
  57.                 }
  58.  
  59.         });
  60.  
  61.  
  62.  
  63.         b3.setOnClickListener(new View.OnClickListener() {
  64.  
  65.                
  66.  
  67.                 public void onClick(View v) {
  68.  
  69.                         this.setChecked(true);
  70.  
  71.                         b1.setChecked(false);
  72.  
  73.                         b2.setChecked(false);
  74.  
  75.  
  76.  
  77.                         /* The Rest Goes Here */
  78.  
  79.                 }
  80.  
  81.         });
  82.  
  83.     }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
nbadal
Developer
Developer
 
Posts: 30
Joined: Tue May 26, 2009 3:55 pm

Postby fhucho » Mon Jun 22, 2009 8:32 pm

nbadal, thanks for reply. If I want the buttons to look jointed, like on the picture (so that they don't look like 3 separate buttons) do I have to somehow set manually the background drawable for left, middle and right buttons? Or is there some way android can do that automatically?
fhucho
Freshman
Freshman
 
Posts: 8
Joined: Mon Jun 22, 2009 9:48 am

Postby fhucho » Mon Jun 22, 2009 8:39 pm

I found out that the new Google Maps have the jointed togle buttons I want - see 0:59 on this video:[youtube]http://www.youtube.com/watch?v=zP7tSXVRCec[/youtube]

I hope this can be done without custom drawables...
fhucho
Freshman
Freshman
 
Posts: 8
Joined: Mon Jun 22, 2009 9:48 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests