Dialog的创建 16-1-第四周

来源:互联网 发布:知乎回答问题在哪里 编辑:程序博客网 时间:2024/06/13 22:31

1.Dialog的创建

创建过程

1.AlertDialog.Builder创建对象

2.setTitle添加标题,setIcon添加图标,setMessage添加消息内容,setNeutralButton //neutral中立的

3.setPositiveButton,setNegativeButton设置按钮

4. .show显示

如何指定对话框内容?

setItems设置对话框内容为简单列表项

setSingleChoiceItems 设置单选框

setMultiChoiceItems 设置多选框


1.基本对话框的创建

AlertDialog.Builder builder=new AlertDialog.builder(this)

                     .setTitle(...)

                     .setMessage(........);

builder.show;

2.方式用接口定义监听器:

AlertDialog.Builder builder=new AlertDialog.builder(this)

                     .setTitle(...);

DialogInterface.OnMultiChoiceClickListener listener=new  DialogInterface.OnMultiChoiceClickListener{

   @Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// TODO Auto-generated method stub
checked[0]=true;
}

}

builder.setMultiChoiceItems(数据,boolean,监听器);

builder.show;

3.自定义列表对话框

.setAdapter(new ArrayAdapter<String>(this,R.layout.xxx,items),null);

4.自定义view对话框

1.写了一个布局TableLayout的布局界面

2.java代码

TableLayout  layout=(TableLayout) getLayoutInflater().inflate(R.layout.xxx,null);

....

builder.setView(layout);

2.TableLayout

用来创建登入界面

  使用tablerow表示一行

3.写一个类继承Application可以用来保存全局数据

public class WmWareHouseApplication extends Application {
private ArrayList<String> mList = new ArrayList<String>();
public ArrayList<String> getmList() {
return mList;
}
public void setmList(ArrayList<String> mList) {
this.mList = mList;
}
}





0 0