左上运营商标记亮了···
<code class="lang-java">package org.kechuang.bbs.acmilan.mycalculator; import android.content.DialogInterface; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainBoard extends AppCompatActivity { private EditText edita; private EditText editb; private EditText editresult; private View.OnClickListener onclickbutton = new View.OnClickListener() { @Override public void onClick(View v) { try { double a = Double.parseDouble(edita.getText().toString()); double b = Double.parseDouble(editb.getText().toString()); double result = 0; switch (v.getId()) { case R.id.btnadd: result = a + b; break; case R.id.btnsub: result = a - b; break; case R.id.btnmul: result = a * b; break; case R.id.btndiv: result = a / b; break; default: throw new Exception("Invalid Button"); } editresult.setText(Double.toString(result)); }catch (Exception e) { Toast.makeText(MainBoard.this, "出现了错误", Toast.LENGTH_LONG).show(); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnadd = (Button)findViewById(R.id.btnadd); Button btnsub = (Button)findViewById(R.id.btnsub); Button btnmul = (Button)findViewById(R.id.btnmul); Button btndiv = (Button)findViewById(R.id.btndiv); btnadd.setOnClickListener(onclickbutton); btnsub.setOnClickListener(onclickbutton); btnmul.setOnClickListener(onclickbutton); btndiv.setOnClickListener(onclickbutton); edita = (EditText)findViewById(R.id.edita); editb = (EditText)findViewById(R.id.editb); editresult = (EditText)findViewById(R.id.editresult); } }</code>
<code class="lang-xml"><?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="org.kechuang.bbs.acmilan.mycalculator.MainBoard"> <linearlayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:weightsum="1"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textAppearanceLarge" android:text="A =" android:id="@+id/textView"> <edittext android:layout_width="match_parent" android:layout_height="wrap_content" android:inputtype="numberDecimal" android:ems="10" android:id="@+id/edita"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textAppearanceLarge" android:text="B =" android:id="@+id/textView2"> <edittext android:layout_width="match_parent" android:layout_height="wrap_content" android:inputtype="numberDecimal" android:ems="10" android:id="@+id/editb"> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="加法" android:id="@+id/btnadd"> </button><button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="减法" android:id="@+id/btnsub"> </button></linearlayout> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="乘法" android:id="@+id/btnmul"> </button><button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="除法" android:id="@+id/btndiv"> </button></linearlayout> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textAppearanceLarge" android:text="结果:" android:id="@+id/textView3"> <edittext android:layout_width="match_parent" android:layout_height="wrap_content" android:inputtype="numberDecimal" android:ems="10" android:id="@+id/editresult"> </edittext></textview></edittext></textview></edittext></textview></linearlayout> </relativelayout></code>
[修改于 9年0个月前 - 2015/12/14 16:19:39]
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |
200字以内,仅用于支线交流,主线讨论请采用回复功能。