string.xml
main.xml
Activity类
运行效果
[img]http://dl.iteye.com/upload/attachment/462746/ad693322-74fa-31f3-91f8-453bae6e7fb7.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/462748/b85e561e-de68-3402-aa75-5d0b1c499113.jpg[/img]
源码 附件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Activity01!</string>
<string name="app_name">android_xhtest_01</string>
<string name="btn">显示普通对话框</string>
<string name="title">普通对话框</string>
<string name="ok">确定</string>
<string name="dialog_msg">这是普通对话框的内容!!!</string>
</resources>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:text=""
android:id="@+id/EditText01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:cursorVisible="false"/>
<Button
android:text="@string/btn"
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Activity类
package xiaohang.zhimeng;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Activity01 extends Activity {
// 普通对话框ID
final int COMMON_DIALOG = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.Button01);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(COMMON_DIALOG);
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case COMMON_DIALOG:
Builder b = new AlertDialog.Builder(this);
b.setIcon(R.drawable.android);
b.setTitle(R.string.btn);
b.setMessage(R.string.dialog_msg);
b.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
EditText et = (EditText) findViewById(R.id.EditText01);
et.setText(R.string.dialog_msg);
}
});
dialog = b.create();
break;
default:
break;
}
return dialog;
}
}
运行效果
[img]http://dl.iteye.com/upload/attachment/462746/ad693322-74fa-31f3-91f8-453bae6e7fb7.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/462748/b85e561e-de68-3402-aa75-5d0b1c499113.jpg[/img]
源码 附件