Android常见控件— — —AlertDialog
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android常见控件— — —AlertDialog相关的知识,希望对你有一定的参考价值。
package com.example.uiwidgettest2;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class AlertDialogActivity extends Activity{
private ProgressBar progressBar = null;
private Button btn1 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edittext);
progressBar = (ProgressBar)findViewById(R.id.progress_bar);
btn1 = (Button)findViewById(R.id.button1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder dialog = new AlertDialog.Builder(AlertDialogActivity.this);
dialog.setTitle("警告框");
dialog.setMessage("内容");
dialog.setCancelable(false);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.show();
}
});
}
以上是关于Android常见控件— — —AlertDialog的主要内容,如果未能解决你的问题,请参考以下文章