第一范文网 - 专业文章范例文档资料分享平台

《Android程序设计》期末总结

来源:用户分享 时间:2025/6/17 17:01:18 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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程序设计》期末总结 的文档
《Android程序设计》期末总结.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0r5j2644s60fvan2h1k1_5.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top