Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 25th, 2012  |  syntax: None  |  size: 2.95 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Switch to different Activities onClick
  2. ImageButton btn1= (ImageButton)findViewById(R.id.timetable);
  3. btn1.setOnClickListener(btnListener1);
  4.  
  5. ImageButton btn2= (ImageButton)findViewById(R.id.location);
  6. btn2.setOnClickListener(btnListener2);
  7. private OnClickListener btnListener1 = new OnClickListener()
  8. {
  9.     public void onClick(View view)
  10.     {                        
  11.          Intent myIntent = new Intent(getBaseContext(), HelloWorld1.class);
  12.          startActivity(myIntent);
  13.     }
  14. };
  15.  
  16. private OnClickListener btnListener2 = new OnClickListener()
  17. {
  18.     public void onClick(View view)
  19.     {                
  20.         Intent myIntent2 = new Intent(getBaseContext(), HelloWorld2.class);        
  21.         startActivity(myIntent2);
  22.     }
  23. };
  24.        
  25. <activity android:name="myApp" android:label="@string/app_name">
  26.     <intent-filter>
  27.         <action android:name="android.intent.action.MAIN" />
  28.         <category android:name="android.intent.category.LAUNCHER" />
  29.     </intent-filter>
  30. </activity>        
  31. <activity android:name=".HelloWorld1"></activity>
  32. <activity android:name=".HelloWorld2"></activity>
  33.        
  34. <?xml version="1.0" encoding="utf-8"?>
  35. <AbsoluteLayout
  36. android:id="@+id/widget34"
  37. android:layout_width="fill_parent"
  38. android:layout_height="fill_parent"
  39. xmlns:android="http://schemas.android.com/apk/res/android"
  40. android:background="#ffffff"
  41. >
  42.  
  43. <GridView
  44.     android:id="@+id/widget36"
  45.     android:layout_width="wrap_content"
  46.     android:layout_height="wrap_content"
  47.     android:numColumns="2"
  48.     android:layout_x="110px"
  49.  
  50.     android:layout_y="32px"
  51.     android:layout_centerInParent="true">
  52. </GridView>
  53. <ImageButton
  54.     android:id="@+id/timetable"
  55.     android:layout_width="wrap_content"
  56.     android:layout_height="wrap_content"
  57.     android:layout_x="210px"
  58.     android:layout_y="142px"
  59.     android:background="@drawable/icon2">
  60. </ImageButton>
  61. <ImageButton
  62.     android:id="@+id/location"
  63.     android:layout_width="wrap_content"
  64.     android:layout_height="wrap_content"
  65.     android:layout_x="100px"
  66.     android:layout_y="342px"
  67.     android:background="@drawable/icon">
  68. </ImageButton>
  69.        
  70. public class HelloAndroid extends Activity {
  71. private Button button_1;
  72. private Button button_2;
  73.  
  74. /** Called when the activity is first created. */
  75. @Override
  76. public void onCreate(Bundle savedInstanceState) {
  77.     super.onCreate(savedInstanceState);
  78.     setContentView(R.layout.main);
  79.     initialiyeFields();
  80. }
  81.  
  82. private void initialiyeFields(){
  83.     button_1 = (Button)findViewById(R.id.button1);
  84.     button_1.setOnClickListener(new OnClickListener() {
  85.         @Override
  86.         public void onClick(View v) {
  87.             Intent intent = new Intent(HelloAndroid.this, HelloWord1.class);
  88.             startActivity(intent);
  89.         }
  90.     });
  91.  
  92.     button_2 = (Button)findViewById(R.id.button2);
  93.     button_2.setOnClickListener(new OnClickListener() {
  94.         @Override
  95.         public void onClick(View v) {
  96.             Intent intent = new Intent(HelloAndroid.this, HelloWord2.class);
  97.             startActivity(intent);
  98.         }
  99.     });
  100. }