編輯:關於Android編程
把常用的對話框記一下,方便以後查用
布局文件
package com.wzw.dialog; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnMultiChoiceClickListener; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } /** * 確定取消對話框 * @param v */ public void click1(View v){ AlertDialog.Builder builder=new Builder(this); builder.setTitle("我是標題"); builder.setMessage("我是提示信息"); builder.setPositiveButton("確定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "確定被點擊啦", 0).show(); } }); builder.setNegativeButton("取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Toast.makeText(getApplicationContext(), "取消被點擊啦", 0).show(); // 什麼都不寫,默認的是關閉對話框 } }); builder.create().show(); } /** * 單選對話框 * @param v */ public void click2(View v){ AlertDialog.Builder builder=new Builder(this); builder.setTitle("我是標題"); final String items[]={"男","女","屌絲"}; builder.setSingleChoiceItems(items, 2, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "性別是"+items[which], 0).show(); dialog.dismiss(); } }); builder.create().show(); } /** * 多選對話框 * @param v */ public void click3(View v){ AlertDialog.Builder builder=new Builder(this); builder.setTitle("我是標題"); final String[] items={"蘋果","香蕉","栗子","西瓜"}; final boolean[] result=new boolean[]{true,false,true,false}; builder.setMultiChoiceItems(items, result, new OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), items[which]+isChecked, 0).show(); result[which]=isChecked; } }); builder.setPositiveButton("提交", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { StringBuffer sb=new StringBuffer(); for (int i = 0; i < result.length; i++) { if(result[i]){ sb.append(items[i]+"--"); } } Toast.makeText(getApplicationContext(), "您的選擇"+sb.toString(), 0).show(); } }); builder.create().show(); } public void click4(View v){ ProgressDialog pd=new ProgressDialog(this); pd.setTitle("提示信息"); pd.setMessage("正在加載數據,請稍等"); pd.show(); } }
本期開始於大家分享幾個簡單又有趣的動畫 效果圖: 效果還是不錯的,而實現起來也並沒有多大的難度,上代碼喽 public int id[] = { R.draw
現在大家很少用短信和飛信發信息了,自從微信出現後,微信可以說已經慢慢替代了短信,飛信,QQ等通信方式,很多朋友都選擇使用微信和朋友們溝通和交流,在節假日的時
Android應用程序窗口的繪圖表面在創建完成之後,我們就可以從上到下地繪制它裡面的各個視圖了,即各個UI元素了。不過在繪制這些UI元素之前,我們還需要從上到下地測量它們
本示例以Servlet為例,演示Android與Servlet的通信。眾所周知,Android與服務器通信通常采用HTTP通信方式和Socket通信方式,而HTTP通信方