android 對話方塊總結

來源:互聯網
上載者:User

標籤:android   對話方塊   

1、AlertDialog對話方塊

AlertDialog.Builder builder=new Builder(HomeActivity.this);builder.setTitle("提示");builder.setMessage("是否刪除資訊?");builder.setPositiveButton("是",new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {new AsyncTask<Void, Void, Void>(){@Overrideprotected Void doInBackground(Void... params) {//同意則把當前資料寫入請假申請表裡if(mRejectLeaveInfoDao==null){mRejectLeaveInfoDao=new RejectLeaveInfosDao(HomeActivity.this);}else{mRejectLeaveInfoDao.deleteLeaveInfo(tmpInfoReject);}fillDataReject();return null;}}.execute();}});builder.setNegativeButton("否",new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {dialog.dismiss();}});builder.create().show();}

2、Dialog對話方塊

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




android 對話方塊總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.