Newb Q: How to switch between views

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

Newb Q: How to switch between views

Postby Iska » Sat Feb 21, 2009 6:05 pm

Hey everyone,

I'm a webdesigner (php, mysql, xml, css etc. etc.) for several years but never worked with Java in a professional way. So I decided to play with the Android SDK to change that which went very good, until I tried to switch between different contentviews (layouts). I've checked the Getting Started pages by Google, but I failed to find a clear example.
What I was trying to do was switching from R.layout.intro (intro.xml) to R.layout.menu (mainmenu.xml), but adding an extra 'setContentView' made the app crash and opening a new activity (which wasn't exactly the way I wanted it) didn't work out either.

I hope some of you could help me with this matter

Thanks in advance,
Iska
PC: C2D E8400@3.8ghz, MSI NEO2-fr P45, OCZ Plat. DDR2-800@846mhz, 2x MSI 4850 CF, 2x 19"W, Win Vista Ult. x64, RAID 0.. Laptop: AMD Turion64 2ghz, 1gb geheugen, Ati X1600, Ubuntu 8.04.. Media-center: AMD 3200+ X2, 1gb geheugen, Win XP, 1x 24"W
Iska
Freshman
Freshman
 
Posts: 2
Joined: Sat Feb 21, 2009 5:51 pm
Location: Den Haag, Netherlands

Top

Postby Iska » Sun Feb 22, 2009 8:39 pm

Okay, I learned that I've got to use the ViewGroups. The only problem left is that when I finally entered all the parameters for the ViewGroup constructer, the compiler tells me: 'Cannot instantiate the type ViewGroup'!
My Code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2.  
  3. import android.os.Bundle;
  4.  
  5. import android.view.Window;
  6.  
  7. import android.view.WindowManager;
  8.  
  9. import android.view.View;
  10.  
  11. import android.view.ViewGroup;
  12.  
  13. import android.view.View.OnClickListener;  
  14.  
  15. import android.widget.TextView;
  16.  
  17. import android.widget.Button;
  18.  
  19. import android.widget.EditText;
  20.  
  21.  
  22.  
  23. //Main class
  24.  
  25. public class CookAssistance extends Activity
  26.  
  27. {
  28.  
  29.         public  ViewGroup       vgViews;
  30.  
  31.        
  32.  
  33.         @Override
  34.  
  35.     //Create functie
  36.  
  37.     public void onCreate(Bundle savedInstanceState)
  38.  
  39.     {
  40.  
  41.         super.onCreate(savedInstanceState);
  42.  
  43.        
  44.  
  45.         //Titel verwijderen
  46.  
  47.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  48.  
  49.        
  50.  
  51.         //Fullscreen
  52.  
  53.         this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  54.  
  55.        
  56.  
  57.         vgViews = new ViewGroup(this.getApplicationContext());
  58.  
  59.        
  60.  
  61.         //Gebruik main.xml voor de layout
  62.  
  63.         setContentView(R.layout.intro);
  64.  
  65.        
  66.  
  67.         onStart(savedInstanceState);
  68.  
  69.     }
  70.  
  71.  
  72.  
  73.         //Start functie
  74.  
  75.     public void onStart(Bundle savedInstanceState)
  76.  
  77.     {
  78.  
  79.        
  80.  
  81.     }
  82.  
  83. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
PC: C2D E8400@3.8ghz, MSI NEO2-fr P45, OCZ Plat. DDR2-800@846mhz, 2x MSI 4850 CF, 2x 19"W, Win Vista Ult. x64, RAID 0.. Laptop: AMD Turion64 2ghz, 1gb geheugen, Ati X1600, Ubuntu 8.04.. Media-center: AMD 3200+ X2, 1gb geheugen, Win XP, 1x 24"W
Iska
Freshman
Freshman
 
Posts: 2
Joined: Sat Feb 21, 2009 5:51 pm
Location: Den Haag, Netherlands

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 5 guests