日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
剖析Android中一個簡單對話框

 一個簡單講述對話框的Android實例,剖析其中的原理,下文直接是代碼。

***步:先配置項目中的res文件夾中values/strings.xml

Java代碼:

 
 
 
  1. 普通對話框
  2. 顯示普通對話框
  3. 普通對話框
  4. 確定
  5. 這是一個普通對話框

第二步:配置項目中的res文件夾中l(wèi)ayout/main.xml 用來創(chuàng)建輸入框和“顯示普通對話框”按鈕

java代碼:

 
 
 
  1. android:orientation="vertical"
  2. android:layout_width="fill_parent"
  3. android:layout_height="wrap_content"
  4. >
  5. android:layout_width="fill_parent" 
  6. android:layout_height="wrap_content" 
  7. android:text="@string/message"/>
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:text="@string/button"/>

第三步:編寫src文件夾包底下的.java文件

java代碼:

 
 
 
  1. package eoe.demo;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.app.AlertDialog.Builder;
  5. import android.app.Dialog;
  6. import android.content.DialogInterface;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. public class CommonDialogActivity extends Activity {
  13. protected static final int COMMON_DIALOG = 1;
  14. /** Called when the activity is first created. */
  15. @Override
  16. public void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.main);
  19. Button button= (Button)findViewById(R.id.button);
  20. View.OnClickListener listener = new View.OnClickListener() {
  21. public void onClick(View arg0) {
  22. // TODO Auto-generated method stub
  23. showDialog(COMMON_DIALOG);
  24. }
  25. };
  26. button.setOnClickListener(listener);
  27. }
  28. /* 
  29. * 使用onCreateDialog(int)來管理對話框的狀態(tài), 
  30. * 那么每次對話框被解除時, 
  31. * 該對話框?qū)ο蟮臓顟B(tài)會被Activity保存. 調(diào)用 
  32. * removeDialog(int)將所有該對象的內(nèi)部引用 
  33. * 移除 如本程序那樣,如果不加removeDialog, 
  34. * 那么顯示的是***次的內(nèi)容 
  35. */
  36. protected Dialog onCreateDialog(int id){
  37. AlertDialog dialog=null;
  38. EditText editText = (EditText) findViewById(R.id.editText);
  39. switch(id){
  40. case COMMON_DIALOG:
  41. Builder builder = new AlertDialog.Builder(this);
  42. builder.setIcon(R.drawable.icon);
  43. builder.setMessage(editText.getText());
  44. builder.setTitle(R.string.title);
  45. DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
  46. public void onClick(DialogInterface arg0, int arg1) {
  47. // TODO Auto-generated method stub
  48. removeDialog(COMMON_DIALOG); 
  49. }
  50. };
  51. builder.setPositiveButton(R.string.ok, listener);
  52. dialog = builder.create();
  53. break;
  54. default:
  55. break;
  56. }
  57. Log.e("onCreateDialog", "onCreateDialog");
  58. return dialog;
  59. }
  60. }

本文名稱:剖析Android中一個簡單對話框
轉(zhuǎn)載源于:http://m.5511xx.com/article/cogoihj.html