Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 對話框總結

android 對話框總結

編輯:關於Android編程

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(){

							@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();
				
				
			}

2、Dialog對話框

new AsyncTask() {
			List apps=new ArrayList();
			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();

對應布局文件:




    

    




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();
	}
	

}

對應布局文件



    
    
    
    
    
     

    

效果圖:




  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved