An example of Android mobile phone software development interface redirection
Development Environment Configuration:
Window server 2008
Eclipse 3.7
JDK1.6
Android2.2
ADT14
// Xml file for application configuration
// AndroidManifest. xml
//--------------------------------------------------------------------------------
<? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "LC. HelloWorld"
Android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
<Uses-sdk android: minSdkVersion = "7"/>
<Application
Android: icon = "@ drawable/ic_launcher"
Android: label = "@ string/app_name">
<Activity
Android: name = ". SecPage"
Android: label = "@ string/app_name">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
<Activity
Android: label = "@ string/app_name"
Android: name = ". HelloWorldActivity">
</Activity>
<Activity
Android: label = "@ string/app_name"
Android: name = ". OtherActivity">
</Activity>
</Application>
</Manifest>
// Xml file for mobile phone interface Layout
Res/layout/main. xml
//----------------------------------------------------------------------------
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
<TextView
Android: id = "@ + id/txt_display"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"/>
<TextView
Android: id = "@ + id/myTextView"
Android: layout_width = "170dp"
Android: layout_height = "wrap_content"
Android: text = "TextView"/>
<Button
Android: id = "@ + id/myButton"
Android: layout_width = "fill_parent"
Android: layout_height = "69dp"
Android: text = "Button"/>
</LinearLayout>
Res/layout/other. xml
//-------------------------------------------------------------------------
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
<TextView
Android: id = "@ + id/myTextView2"
Android: layout_width = "170dp"
Android: layout_height = "wrap_content"
Android: text = "TextView"/>
<Button
Android: id = "@ + id/btn_back"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "back rollback"/>
</LinearLayout>
Res/values/strings. xml
//-------------------------------------------------------------------------
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "hello"> Hello World, HelloWorldActivity! </String>
<String name = "app_name"> HelloWorld </string>
<String name = "other"> otherActivity </string>
</Resources>
// Source code
// SecPage. java
//-------------------------------------------------------------------------
Package LC. HelloWorld;
Import android. app. Activity; // the package of the Activity
Import android. content. DialogInterface;
Import android. content. DialogInterface. OnClickListener;
Import android. content. Intent;
Import android. OS. Bundle; // used to map string values
Import android. view. View;
Import android. widget. Button;
Import android. widget. TextView;
Public class SecPage extends Activity
{
Button myButton = null;
@ Override
Public void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main); // set the current view as the main interface Layout R. layout. main
// Add a click event to the button
MyButton = (Button) this. findViewById (R. id. myButton );
MyButton. setText ("jump to another Interface Activity ");
MyButton. setOnClickListener (new MyButtonListener ());
}
Class MyButtonListener implements android. view. View. OnClickListener
{
@ Override
Public void onClick (View v)
{
// Generate an Intent object
// Intent is an abstract description that provides direct interaction between activities and can be run by startActivty.
// Intent provides a media to call each other,
// Implement the decoupling between the caller and the called.
Intent intent = new Intent ();
Intent. setClass (SecPage. this, OtherActivity. class );
Intent. putExtra ("testExtra", "haha! ");
SecPage. this. startActivity (intent );
}
}
}
// OtherActivity. java
//---------------------------------------------------------------------------
/**
*
*/
Package LC. HelloWorld;
Import android. app. Activity;
Import android. content. Intent;
Import android. view. View;
Import android. OS. Bundle;
Import android. widget. TextView;
Import android. widget. Button;
/**
* @ Author Administrator
*
*/
Public class OtherActivity extends Activity {
@ Override
Protected void onCreate (Bundle savedInstanceState)
{
Super. onCreate (savedInstanceState );
SetContentView (R. layout. other );
// Set
TextView myTextView = null;
// Get the extension parameters set on the previous page?
Intent intent = this. getIntent ();
String mytext = intent. getStringExtra ("testExtra ");
If (mytext! = Null & mytext. length () <= 0)
{
Mytext = "haha_1 ";
}
Mytext + = ", I skipped it! ";
// Set the content of the text box
MyTextView = (TextView) this. findViewById (R. id. myTextView2 );
MyTextView. setText (mytext );
// Btn_back Add back button click process event
Button btn_back = (Button) this. findViewById (R. id. btn_back );
Btn_back.setOnClickListener (new BackClickListener ());
}
// Define the Add rollback button and click process event
Class BackClickListener implements android. view. View. OnClickListener
{
@ Override
Public void onClick (View v)
{
Intent intent = new Intent ();
Intent. setClass (OtherActivity. this, SecPage. class );
Intent. putExtra ("testExtra", "haha! ");
OtherActivity. this. startActivity (intent );
}
}
}
// -- The --- end ----
// 2011-11-17
// Vp: hsg