首页 > 代码库 > 纯属娱乐,对入门Android有一定的帮助
纯属娱乐,对入门Android有一定的帮助
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/
} else {网站源码下载
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);
}
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。