《Android程序设计》期末总结

2026/1/26 20:00:40

setTitle(\开始游戏!\ break; case ITEM2: setTitle(\退出!\ break; } return true; }

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(0, ITME3, 0, \红色背景\ menu.add(0, ITME4, 0, \绿色背景\ menu.add(0, ITME5, 0, \白色背景\ } public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case ITME3: myTV.setBackgroundColor(Color.RED); break; case ITME4: myTV.setBackgroundColor(Color.GREEN); break; case ITME5: myTV.setBackgroundColor(Color.WHITE); break; } return true; } }

3.D.5 演示提示对话框的使用 AlertDialogActivity.java

public class AlertDialogActivity extends Activity { private TextView myTV; private Button myBtn; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myTV = (TextView) findViewById(R.id.TextView01); myBtn = (Button) findViewById(R.id.Button01); final AlertDialog.Builder builder = new AlertDialog.Builder(this); myBtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { builder.setMessage(\真的要删除该记录吗?\

.setPositiveButton(\是\ new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { myTV.setText(\删除成功!\ } }) .setNegativeButton(\否\ new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { myTV.setText(\取消删除!\ } }); AlertDialog ad = builder.create(); ad.show(); } }); } }

3.D.6 Toast的创建及显示 ToastActivity.java

public class ToastActivity extends Activity { private Button b1, b2; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); b1 = (Button) findViewById(R.id.Button01); b2 = (Button) findViewById(R.id.Button02); b1.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast t1 = Toast.makeText(getApplicationContext(), \我多显示一会儿!\ Toast.LENGTH_LONG); t1.show(); } }); b2.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast t2 = Toast.makeText(getApplicationContext(), \我少显示一会儿!\ Toast.LENGTH_SHORT); t2.show(); }

}

}

});

3.D.7使用Toast显示注册信息

RegActivity.Java

public class RegActivity extends Activity { // 声明组件 private Button register, cancel; private ToggleButton marriged; private RadioButton male, female; private EditText username, password; private Spinner position; private CheckBox reading, swimming; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); male = (RadioButton) findViewById(R.id.male); female = (RadioButton) findViewById(R.id.female); reading = (CheckBox) findViewById(R.id.reading); swimming = (CheckBox) findViewById(R.id.swimming); marriged = (ToggleButton) findViewById(R.id.marriged); position = (Spinner) findViewById(R.id.position); String[] strs = { \ ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, strs); position.setAdapter(aa); register = (Button) findViewById(R.id.register); cancel = (Button) findViewById(R.id.cancel); register.setOnClickListener(new OnClickListener() { public void onClick(View v){

Toast.makeText(getApplicationContext(), \ Toast.LENGTH_LONG).show();

Toast.makeText(getApplicationContext(), \ Toast.LENGTH_LONG).show(); if (male.isChecked()) {

Toast.makeText(getApplicationContext(), \ } else {

Toast.makeText(getApplicationContext(), \ } String temp = \ if (reading.isChecked()) { temp += \ } if (swimming.isChecked()) { temp += \ }

Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_LONG).show(); if (marriged.isChecked()) {

Toast.makeText(getApplicationContext(), \ } else { Log.i(\

Toast.makeText(getApplicationContext(), \ }

Toast.makeText(getApplicationContext(), \ Toast.LENGTH_LONG).show(); } }); } }

第四章代码

① 通过Intent实现多Activity的Android应用的启动

public class Activity1 extends Activity {

public void onCreate(Bundle savedInstanceState) { RadioGroup RG_OS;

RadioButton RG_OS_RB1, RG_OS_RB2, RG_OS_RB3; Button button_submit, button_back; super.onCreate(savedInstanceState); setContentView(R.layout.activity1);

RG_OS = (RadioGroup) findViewById(R.id.RG_OS);

RG_OS_RB1 = (RadioButton) findViewById(R.id.RG_OS_RB1); RG_OS_RB2 = (RadioButton) findViewById(R.id.RG_OS_RB2); RG_OS_RB3 = (RadioButton) findViewById(R.id.RG_OS_RB3); button_submit = (Button) findViewById(R.id.button_submit);


《Android程序设计》期末总结.doc 将本文的Word文档下载到电脑
搜索更多关于: 《Android程序设计》期末总结 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219