今天写了第一个android程序,完美在手机端运行。
核心代码如下
Button button1 = (Button) findViewById(R.id.calculation_button)
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str1 = ""
EditText addend = (EditText) findViewById(R.id.text1)
str1=addend.getText().toString()
int a = Integer.parseInt(str1)
String str2 = ""
EditText augend = (EditText) findViewById(R.id.text2)
str2=augend.getText().toString()
int b = Integer.parseInt(str2)
TextView result = (TextView) findViewById(R.id.result)
result.setText(String.valueOf(a+b))
}
})
其他一些控件的定义的什么的就不详说了,很简单的东西。