对话框的设计
杜勇 计应111班
对于对话框这个词的概念相信大家都不是很陌生,因为我们都知道在一些游戏或者网页错误
的时候我们都经常会看到弹出一个提示的对话框。因此在android系统的开发中,对话框的设计
也是不可缺少的。在这里,我们演示一个比较简单的例子,程序的代码如下:
package com.c;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.widget.Button;
public class LingActivity extends Activity {
/** Called when the activity is first created. */
Dialog dialog = new AlertDialog.Builder(this).setIcon(
android.R.drawable.btn_star).setTitle("喜好调查").setMessage(
"你喜欢李连杰的电影吗?").setPositiveButton("很喜欢",
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "我很喜欢他的电影。",
Toast.LENGTH_LONG).show();
}
}).setNegativeButton("不喜欢", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "我不喜欢他的电影。", Toast.LENGTH_LONG)
.show();
}
}).setNeutralButton("一般", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "谈不上喜欢不喜欢。", Toast.LENGTH_LONG)
.show();
}
}).create();
dialog.show(); // 1
}
其中期待的结果如下图:
这一次的作业练习中,我是真心的痛苦啊,做了好久好久都总是运行不起,我检查了很久,
发现了代码上并没有问题,但是在ADV上的运行结果却总是没有动静。实在是没有办法了,于
是我就向我的同学询问了一下,天!才发现是一个简单的问题,那就是没有把配置的版本设置
为JDK1.6的。。。。我真是无语了。。。。。
于是,我从其中明白了一个道理,那就是:有的时候人真的不应该钻牛角尖,当你碰到一个
难题解决不了而又不能发现问题的时候,你不妨回过头来看一看、想一想,也许你的问题能够迎
刃而解,因为那只是一个非常简单的问题。