package android.m9;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class helloWorld extends Activity {
private TextView logo;
private EditText et;
private Button reset, submit;
private EditText result;
private String name;
private String lastName = "";
private int rp;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// /////////////////////////////////////////////
// logo set
logo = (TextView) findViewById(R.id.TextView_1);
logo.setText(R.string.logo);
// ////////////////////////////////////////////
// EditText set
et = (EditText) findViewById(R.id.EditText_1);
et.setText(R.string.inputTip);
// ////////////////////////////////////////////
// Button set:reset
reset = (Button) findViewById(R.id.Button_1);
reset.setText(R.string.reset);
reset.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
et.setText(R.string.inputTip);
result.setText("");
}
});
//Button set:reset
submit = (Button) findViewById(R.id.Burron_2);
submit.setText(R.string.submit);
submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
name = et.getText().toString();
if (!lastName.equals(name)) {
rp = (int) (Math.random() * 100);
result.setText("测试者姓名:" + name + "\n\n" + "人品得分:" + rp);
lastName = name;http://www.huiyi8.com/webyuanma/
result.setText("请更换测试者!\n\n测试者姓名:" + name + "\n\n"
+ "人品得分:" + rp);
}
}
});
// ////////////////////////////////////////////
// TextView set
result = (EditText) findViewById(R.id.EditText_2);
result.setEnabled(false);
result.setTextColor(android.graphics.Color.BLUE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 1, 1, R.string.exit);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == 1) {
finish();
}
return super.onOptionsItemSelected(item);
}
}
纯属娱乐,对入门Android有一定的帮助,布布扣,bubuko.com
纯属娱乐,对入门Android有一定的帮助
原文:http://www.cnblogs.com/xkzy/p/3804330.html