本帖最後由 周政輝 於 2018-9-1 11:59 編輯
MainActivity- package com.example.student.myapplication;
- import android.content.Intent;
- import android.net.Uri;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- Button btn0;
- Button btn1;
- Button btn2;
- Button btn3;
- Button btn4;
- Button btn5;
- Button btn6;
- Button btn7;
- Button btn8;
- Button btn9;
- Button btn10;
- Button btn11;
- Button call;
- TextView number;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Init();
- }
- Button.OnClickListener listener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Button tmp = (Button) findViewById(v.getId());
- number.setText(number.getText().toString() + tmp.getText().toString());
- }
- };
- private void Init() {
- btn0 = (Button) findViewById(R.id.button0);
- btn0.setOnClickListener(listener);
- btn1 = (Button) findViewById(R.id.button1);
- btn1.setOnClickListener(listener);
- btn2 = (Button) findViewById(R.id.button2);
- btn2.setOnClickListener(listener);
- btn3 = (Button) findViewById(R.id.button3);
- btn3.setOnClickListener(listener);
- btn4 = (Button) findViewById(R.id.button4);
- btn4.setOnClickListener(listener);
- btn5 = (Button) findViewById(R.id.button5);
- btn5.setOnClickListener(listener);
- btn6 = (Button) findViewById(R.id.button6);
- btn6.setOnClickListener(listener);
- btn7 = (Button) findViewById(R.id.button7);
- btn7.setOnClickListener(listener);
- btn8 = (Button) findViewById(R.id.button8);
- btn8.setOnClickListener(listener);
- btn9 = (Button) findViewById(R.id.button9);
- btn9.setOnClickListener(listener);
- btn10 = (Button) findViewById(R.id.button10);
- btn10.setOnClickListener(listener);
- btn11 = (Button) findViewById(R.id.button11);
- btn11.setOnClickListener(listener);
- call = (Button) findViewById(R.id.call);
- number = (TextView) findViewById(R.id.Number);
- }
- public void PhoneCall(View view) {
- Intent dial = new Intent();
- dial.setAction("android.intent.action.CALL");
- dial.setData(Uri.parse("tel:"+ number.getText().toString()));
- startActivity(dial);
- }
- }
複製代碼 Xml: |