《移动应用开发》课程第五次实验,在Android Studio中构建拨号面板

1、在Android Studio中,构建如下图的拨号面板。

  

在点击拨号面板中的12个按键,在面板上方区域追加显示按键对应的字符,当字符数量超出面板上方区域的显示范围(大于16个字符),则停止显示更多的字符[1],并以Toast方式提示用户“输入号码超出有效长度”;点击面板右下方的删除按钮,点击一次,则删除面板上方的一个字符,直至删除全部的字符,并以Toast方式提示用户“已清空全部号码”。

点击屏幕下方的绿色拨号按钮,则跳转到呼叫面板,并显示呼叫的号码和呼叫操作状态[2](参见下图)。

 

运行效果

文件目录

HuJiaoYeMian.java

package com.example.thefifthexperiment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class HuJiaoYeMian extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hu_jiao_ye_mian);
        Intent intent = getIntent();

        String receivedData = intent.getStringExtra("key_data");
        TextView textView = findViewById(R.id.tv_number);
        textView.setText(receivedData);

        ImageView iv_guaduandianhua = findViewById(R.id.iv_guadianhua);
        iv_guaduandianhua.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        finish();
    }
}

MainActivity.java

package com.example.thefifthexperiment;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private RelativeLayout relativeLayout1,relativeLayout2,relativeLayout3,relativeLayout4,relativeLayout5,relativeLayout6,
                       relativeLayout7,relativeLayout8,relativeLayout9,relativeLayout0,relativeLayout_xing,relativeLayout_jing;
private ImageView imageView_bohao,imageView_shanchu;
private TextView showText;
private Context context = this;
private String numbrText="";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        setListener();
    }

    private void setListener() {
        relativeLayout0.setOnClickListener(this);
        relativeLayout1.setOnClickListener(this);
        relativeLayout2.setOnClickListener(this);
        relativeLayout3.setOnClickListener(this);
        relativeLayout4.setOnClickListener(this);
        relativeLayout5.setOnClickListener(this);
        relativeLayout6.setOnClickListener(this);
        relativeLayout7.setOnClickListener(this);
        relativeLayout8.setOnClickListener(this);
        relativeLayout9.setOnClickListener(this);
        relativeLayout_xing.setOnClickListener(this);
        relativeLayout_jing.setOnClickListener(this);

        imageView_shanchu.setOnClickListener(this);
        imageView_bohao.setOnClickListener(this);
    }

    private void initView() {
        relativeLayout0=findViewById(R.id.number0);
        relativeLayout1=findViewById(R.id.number1);
        relativeLayout2=findViewById(R.id.number2);
        relativeLayout3=findViewById(R.id.number3);
        relativeLayout4=findViewById(R.id.number4);
        relativeLayout5=findViewById(R.id.number5);
        relativeLayout6=findViewById(R.id.number6);
        relativeLayout7=findViewById(R.id.number7);
        relativeLayout8=findViewById(R.id.number8);
        relativeLayout9=findViewById(R.id.number9);
        relativeLayout_jing=findViewById(R.id.number_jing);
        relativeLayout_xing=findViewById(R.id.number_xing);

        imageView_bohao=findViewById(R.id.bohao);
        imageView_shanchu=findViewById(R.id.shanchu);

        showText=findViewById(R.id.showText);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.number0:
                if(numbrText.length()==16){
                    Toast.makeText(context,"输入号码超出有效长度",Toast.LENGTH_SHORT).show();
                    break;
                }
                else {
                numbrText=numbrText+"0";
                    break;}
            case R.id.number1:
                if(numbrText.length()==16){
                    Toast.makeText(context,"输入号码超出有效长度",Toast.LENGTH_SHORT).show();
                    break;
                }
                else {
                    numbrText=numbrText+"1";
                    break;}
            case R.id.number2:
                if(numbrText.length()==16){
                    Toast.makeText(context,"输入号码超出有效长度",Toast.LENGTH_SHORT).show();
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值