80,349
社区成员
发帖
与我相关
我的任务
分享
symbol.setText(Activity03.this.getResources().getString(R.string.symbol));
package com.zhoujl.android.calculator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class CalculatorAvtivity extends Activity {
private EditText et1,et2;
private TextView tv1;
private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById();
setListener();
}
private void findViewById() {
et1 = (EditText)findViewById(R.id.et1);
et2 = (EditText)findViewById(R.id.et2);
button = (Button)findViewById(R.id.button1);
}
private void setListener() {
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String number1 = et1.getText().toString().trim();
String number2 = et2.getText().toString().trim();
Intent intent = new Intent();
intent.setClass(CalculatorAvtivity.this, Result.class);
intent.putExtra("number1", number1);
intent.putExtra("number2", number2);
startActivity(intent);
}
});
}
}
package com.zhoujl.android.calculator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class Result extends Activity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
tv = (TextView)findViewById(R.id.tv);
Intent intent = getIntent();
float number1 = Float.parseFloat(intent.getStringExtra("number1"));
float number2 = Float.parseFloat(intent.getStringExtra("number2"));
tv.setText("结果是"+(number1+number2));
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<EditText android:id="@+id/et1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText android:id="@+id/et2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cal"
/>
<Button android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zhoujl.android.calculator"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".CalculatorAvtivity"
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=".Result">
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, CalculatorAvtivity!</string>
<string name="app_name">Calculator</string>
<string name="cal">加</string>
<string name="button">计算</string>
</resources>