com.example.mr18_xzvon.myapplication; android.app.Activity; android.os.Bundle; android.support.design.widget.FloatingActionButton; android.support.design.widget.Snackbar; android.support.v7.app.AppCompatActivity; android.support.v7.widget.Toolbar; android.view.View; android.view.Menu; android.view.MenuItem; android.widget.Button; android.widget.EditText; MainActivity Activity View.OnClickListener{ Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;Button ;EditText ;Boolean ; onCreate(Bundle savedInstanceState) { .onCreate(savedInstanceState); setContentView(R.layout.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (Button) findViewById(R.id.); = (EditText) findViewById(R.id.);.setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); .setOnClickListener(); } onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu., menu); ; } onOptionsItemSelected(MenuItem item) { id = item.getItemId(); (id == R.id.) { ; } .onOptionsItemSelected(item); } onClick(View v) { String str=.getText().toString(); =; (v.getId()){ R.id.: R.id.: R.id.: R.id.: R.id.: R.id.: R.id.: R.id.: R.id.: R.id.: R.id.: (==){ =; str=; .setText(); } .setText(str + ((Button) v).getText()); ; R.id.: R.id.: R.id.: R.id.: (==){ =; str=; .setText(); } .setText(str++((Button)v).getText()+); ; R.id.: =; str=; .setText(); ; R.id.: (==){ =; str=; .setText(); }(str!=&&!str.equals()) .setText(str.substring(,str.length()-)); ; R.id.: getResult(); ; } } getResult(){ String exp=.getText().toString(); (exp==||exp.equals()){ ; } (!exp.contains()){ ; } (){ =; ; } =; result =; String s1=exp.substring(,exp.indexOf()); String op=exp.substring(exp.indexOf()+,exp.indexOf()+); String s2=exp.substring(exp.indexOf()+); (!s1.equals()&&!s2.equals()){ d1=Double.(s1); d2=Double.(s2); (op.equals()){ result=d1+d2; } (op.equals()){ result=d1-d2; } (op.equals()){ result=d1*d2; } (op.equals()){ (d2!=) result= d1/d2; result=; } (!s1.contains()&&!s2.contains()&&!op.equals()){ r= ()result; .setText(r+); }{ .setText(result+); } }(!s1.equals()&&s2.equals()){ .setText(exp); }(s1.equals()&&!s2.equals()){ d2=Double.(s2); (op.equals()){ result=+d2; } (op.equals()){ result=-d2; } (op.equals()){ result=; } (op.equals()){ result=; } (!s2.contains()){ r= ()result; .setText(r+); }{ .setText(result+); } }{ .setText(); } } }
相关分类