Android 的一些提示框
来源:互联网 发布:网络舆情应对应急预案 编辑:程序博客网 时间:2024/05/17 07:54
1.在测试时,如何实现一个提示
可以使用
- Toast.makeText(this, "这是一个提示", Toast.LENGTH_SHORT).show();
- //从资源文件string.xml 里面取提示信息
- Toast.makeText(this, getString(R.string.welcome), Toast.LENGTH_SHORT).show();
这个提示会几秒钟后消失
2.可以使用AlertDialog.Builder 才产生一个提示框.
例如像messagebox那样的
- new AlertDialog.Builder(this)
- .setTitle("Android 提示")
- .setMessage("这是一个提示,请确定")
- .show();
带一个确定的对话框
- new AlertDialog.Builder(this)
- .setMessage("这是第二个提示")
- .setPositiveButton("确定",
- new DialogInterface.OnClickListener(){
- public void onClick(DialogInterface dialoginterface, int i){
- //按钮事件
- }
- })
- .show();
AlertDialog.Builder 还有很多复杂的用法,有确定和取消的对话框
- new AlertDialog.Builder(this)
- .setTitle("提示")
- .setMessage("确定退出?")
- .setIcon(R.drawable.quit)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- setResult(RESULT_OK);//确定按钮事件
- finish();
- }
- })
- .setNegativeButton("取消", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- //取消按钮事件
- }
- })
- .show();
3.menu 的用法.
4.Activity 的切换
2个Activity 的切换,没有数据传递
- //从A到B
- Intent intent = new Intent();
- intent.setClass(A.this, B.class);
- startActivity(intent);
2个Activity 之间传递数据
相关的几个函数
startActivityForResult
public final void setResult(int resultCode, String data)
回调函数
protected void onActivityResult(int requestCode, int resultCode, Intent data)
例如A到B,从B得到数据
- //A到B
- static final int RG_REQUEST = 0;
- Intent intent = new Intent();
- intent.setClass(A.this, B.class);
- startActivityForResult(intent,RG_REQUEST);
- //在B中处理
- Bundle bundle = new Bundle();
bundle.putString("DataKey", edittext.getText().toString());//给bundle 写入数据
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish(); - //最后在A的回调函数里面接收数据
- if (requestCode == RG_REQUEST) {
if (resultCode == RESULT_CANCELED)
setTitle("Canceled...");
else if(resultCode == RESULT_OK) {
setTitle((String)data.getCharSequenceExtra("DataKey"));
}
}
- Android 的一些提示框
- Android 的一些提示框
- Android 的一些提示框与activity 切换
- Android中一些提示的实现方法
- android的一些提示框 以及activity之间数据的传递
- android的一些提示框 以及activity之间数据的传递 .
- JOptionPane 提示框的一些常用方法
- JOptionPane提示框的一些常用方法
- 一些Android开发小提示
- Phonegap-Android的提示框
- 程序命名的一些提示
- 程序命名的一些提示
- 关于SM的一些提示
- 程序命名的一些提示
- 一些错误提示的中文翻译
- git的一些错误提示
- python的一些错误提示
- 网站的一些状态提示
- Castle ActiveRecord 配置
- 好听的纯音乐
- WS-Addressing在CXF和AXIS2中的实际应用
- 获取本机IP地址
- 200条家装小常识
- Android 的一些提示框
- 【IT 系列之12A】开明关系正式开业(2)
- 度量时间差(转载)
- 边框(border)边距(margin)和间隙(padding)属性的
- spring2.5+struts2.1.8+hibernate3整合配置
- 【IT 系列之12B】开明关系正式开业(3)
- 支持 UCenter 建站程序一览表
- pt,px,em,percent转换
- Struts 的标签库 Struts bean write 输出 格式化 标签