Android basic (Activity)

Source: Internet
Author: User

Package ahu.edu;
 
Import android. app. Activity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. view. Menu;
Import android. view. MenuItem;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. TextView;
 
Public class Activity03Activity extends Activity {

 

Private EditText factorOne;
Private EditText factorTwo;
Private TextView symbol;
Private Button calculate;
 
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );

FactorOne = (EditText) findViewById (R. id. factorOne );
FactorTwo = (EditText) findViewById (R. id. factorTwo );
Symbol = (TextView) findViewById (R. id. symbol );
Calculate = (Button) findViewById (R. id. calculate );
Symbol. setText (R. string. symbol );
Calculate. setText (R. string. calculate );
Calculate. setOnClickListener (new CalcualteListener ());
}

Class CalcualteListener implements OnClickListener {
Public void onClick (View v ){
String factorOneStr = factorOne. getText (). toString ();
String factorTwoStr = factorTwo. getText (). toString ();
Intent intent = new Intent ();
Intent. putExtra ("one", factorOneStr );
Intent. putExtra ("two", factorTwoStr );
Intent. setClass (Activity03Activity. this, ResualActivity. class );
Activity03Activity. this. startActivity (intent );
}
}

Public boolean onCreateOptionsMenu (Menu menu ){
Menu. add (0, 1, 1, R. string. exit );
Menu. add (0, 2, 2, R. string. about );
Return super. onCreateOptionsMenu (menu );
}

Public boolean onOptionsItemSelected (MenuItem item ){
If (item. getItemId () = 1 ){
// Finish (); // ---- gentle Method
System. exit (0); // --- cruel method
}
Return super. onOptionsItemSelected (item );
}
 
}
[Java]
Package ahu.edu;
 
Import android. app. Activity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. widget. TextView;
 
Public class ResualActivity extends Activity {
Private TextView resultView;


Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. result );
ResultView = (TextView) findViewById (R. id. result );
Intent intent = getIntent ();
String factorOneString = intent. getStringExtra ("one ");
String factorTwoString = intent. getStringExtra ("two ");
Int factorOneInt = Integer. parseInt (factorOneString );
Int factorTwoInt = Integer. parseInt (factorTwoString );
Int result = factorOneInt * factorTwoInt;
ResultView. setText (result + "");
}
}

[Html]
<? 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: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"/>
<EditText
Android: id = "@ + id/factorOne"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: hint = "@ string/message"
Android: inputType = "none"/>
<TextView
Android: id = "@ + id/symbol"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = ""/>
<EditText
Android: id = "@ + id/factorTwo"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: hint = "@ string/message"
Android: inputType = "none"/>
<Button
Android: id = "@ + id/calculate"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>


</LinearLayout>

[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "ahu.edu"
Android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
 
<Uses-sdk android: minSdkVersion = "10"/>
 
<Application
Android: icon = "@ drawable/ic_launcher"
Android: label = "@ string/app_name">
<Activity
Android: name = ". Activity03Activity"
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: name = ". ResualActivity"
Android: label = "@ string/app_name">

</Activity>
</Application>
 
</Manifest>

 

 

From Yours love affair

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.