andriod studio编写简单计算器

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
//import kotlinx.android.synthetic.main.activity_start.*;

public class MainActivity extends AppCompatActivity {

//文本 add

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView textviewx=(TextView)findViewById(R.id.editText_x);
        final TextView textviewy=(TextView)findViewById(R.id.editText_y);
        final TextView textviewz=(TextView)findViewById(R.id.editText_z);
        final Button mButtonqeual = (Button) findViewById(R.id.button_equal);
        mButtonqeual.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {
                double m_x,m_y,m_z;
                m_x= Double.parseDouble(textviewx.getText().toString());
               m_y= Double.parseDouble(textviewy.getText().toString());
                m_z = m_x+m_y;
                textviewz.setText(String.valueOf(m_z));
        }
        });


    }


}

你可能感兴趣的:(安卓studio)