1、AlertDialog对话框
AlertDialog.Builder builder=new Builder(HomeActivity.this); builder.setTitle("提示"); builder.setMessage("是否删除信息?"); builder.setPositiveButton("是",new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new AsyncTask<Void, Void, Void>(){ @Override protected Void doInBackground(Void... params) { //同意则把当前数据写入请假申请表里 if(mRejectLeaveInfoDao==null){ mRejectLeaveInfoDao=new RejectLeaveInfosDao(HomeActivity.this); }else{ mRejectLeaveInfoDao.deleteLeaveInfo(tmpInfoReject); } fillDataReject(); return null; } }.execute(); } }); builder.setNegativeButton("否",new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); }
new AsyncTask<Void,Object, Void>() { List<VirusApp> apps=new ArrayList<VirusApp>(); String desc=null; Dialog dialog=new Dialog(KillVirusActivity.this); View viewKilling=View.inflate(KillVirusActivity.this,R.layout.killing_dialog,null); @Override protected void onPreExecute() { mKillVirusResult.setText("正在扫描中,请稍等..."); dialog.setCancelable(false); dialog.setContentView(viewKilling); dialog.show();
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="病毒扫描中..." android:textSize="15sp" /> </LinearLayout>
3、activity对话框
activity代码:
package com.example.yqqmobilesafe; import com.example.yqqmobilesafe.db.dao.KeyWordInfoDao; import com.example.yqqmobilesafe.domain.KeyWordInfo; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class AddKeyWordsInfosDailogActivity extends Activity { protected static final int ADD_KEY_INFO_SCUCESS = 100; private EditText et_key_words_input;//输入关键字 private EditText et_key_words_decribe; private Button mSure;//确定 private Button mCancel;//取消 public AddKeyWordsInfosDailogActivity() { } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //去除title requestWindowFeature(Window.FEATURE_NO_TITLE); //去掉Activity上面的状态栏 getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN); setContentView(R.layout.add_keyword_info_activity); init(); setListener(); } private void setListener() { mSure.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { KeyWordInfoDao dao=new KeyWordInfoDao(getApplicationContext()); if(et_key_words_input.getText().toString().trim().length()==0){ Toast.makeText(AddKeyWordsInfosDailogActivity.this,"请输入关键字或者取消!",300).show(); return; } if(et_key_words_decribe.getText().toString().trim().length()==0){ Toast.makeText(AddKeyWordsInfosDailogActivity.this,"请输入关键字描述内容或者取消!",300).show(); return; } KeyWordInfo info=new KeyWordInfo(); info.setKey_word_info(et_key_words_input.getText().toString().trim()); info.setKey_word_decribe(et_key_words_decribe.getText().toString().trim()); //把拦截关键字加入数据库 dao.addKeyWordInfos(info); info=null; setResult(ADD_KEY_INFO_SCUCESS, getIntent()); AddKeyWordsInfosDailogActivity.this.finish(); } }); mCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AddKeyWordsInfosDailogActivity.this.finish(); } }); } private void init() { et_key_words_input=(EditText) findViewById(R.id.et_key_words_input); et_key_words_decribe=(EditText) findViewById(R.id.et_key_words_decribe); mSure=(Button) findViewById(R.id.btn_sure); mCancel=(Button) findViewById(R.id.btn_cancel); } @Override protected void onDestroy() { super.onDestroy(); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="添加关键字" android:gravity="center" /> <TextView android:layout_marginTop="10dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="请输入需要拦截的关键字(最多16个字,允许汉字,字母,数字)" android:gravity="center" /> <EditText android:id="@+id/et_key_words_input" android:layout_marginTop="5dp" android:layout_width="match_parent" android:layout_height="55dp" /> <EditText android:id="@+id/et_key_words_decribe" android:layout_marginTop="5dp" android:layout_width="match_parent" android:layout_height="55dp" android:hint="输入描述内容" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn_cancel" android:layout_width="160dp" android:layout_height="55dp" android:text="取消" android:layout_alignParentLeft="true" android:background="@drawable/sure_cancel_selector" /> <Button android:id="@+id/btn_sure" android:layout_toRightOf="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="55dp" android:layout_alignParentRight="true" android:text="确定" android:background="@drawable/sure_cancel_selector" /> </RelativeLayout> </LinearLayout>
原文地址:http://blog.csdn.net/u014600432/article/details/41309365