##繼承 介面 實作 / 抽象類別 override
## alt + enter 快速引入package
###E:\android\Intent01\app\src\main\java\com\example\intent01\MainActivity.java
package com.example.intent01;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void button_Click(View v){
Intent intent = new Intent(this,SecondActivity.class);
startActivity(intent);
}
public void button01_Click(View v){
Intent intent = new Intent(this,ThreeActivity.class);
startActivity(intent);
}
}
###E:\android\Intent01\app\src\main\java\com\example\intent01\SecondActivity.java
package com.example.intent01;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
public void button2_Click(View v){
finish();
}
}
###E:\android\Intent01\app\src\main\java\com\example\intent01\ThreeActivity.java
package com.example.intent01;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class ThreeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three);
}
public void button2_Click(View v){
finish();
}
}
package com.example.intent02;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class FActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_f);
convertTempture();
}
public void convertTempture(){
int c;
double f = 0.0;
Bundle bundle = this.getIntent().getExtras();
if(bundle != null){
c = Integer.parseInt(bundle.getString("TEMPC"));
f = (9.0 * c) / 5 + 32;
TextView o = findViewById(R.id.lblOutput);
o.setText("華氏溫度:"+Double.toString(f));
}
}
public void button2_Click(View V){
finish();
}
}
package com.example.intent02;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void button_Click(View V){
EditText txtC = findViewById(R.id.txtC);
Intent intent = new Intent(this,FActivity.class);
Bundle bundle = new Bundle();
bundle.putString("TEMPC",txtC.getText().toString());
intent.putExtras(bundle);
startActivity(intent);
}
}