您的位置:首页 > 移动开发 > Android开发

android中AlertDialog 中setView用法的一些小结

2013-12-08 10:41 591 查看
对于AlertDialog中setView的用法,可以通过自定义一个View,设计成自己想要的不同的dialog,

在MainActivity中:

private LayoutInflater mLayoutInflater;
private View view;


mLayoutInflater=LayoutInflater.from(this);
view=mLayoutInflater.inflate(R.layout.input_dailog, null);


在Layout布局文件中,设置一个EditText和TextView组成的水平布局input_dailog.xml.

public void showCustomInputDialog(final int position, boolean isInputNumber) {
// 注意MainActivity如有自己的布局文件,这个dialog是view的布局文件,一定要把View写上
tv_dialog=(TextView) view.findViewById(R.id.textView_dialog_tv);

et_dialog=(EditText) view.findViewById(R.id.editText_dialog_et);

if (isInputNumber) {
et_dialog.setKeyListener(new DigitsKeyListener(false, true));
}

/*Dialog dialog = new MyDialog(PublishActivity.this,R.style.MyDialog);
dialog.show();*/

AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle(getResources().getString(R.string.txt_please_custom_input));

builder.setView(view);
builder.setPositiveButton(getResources().getString(R.string.txt_define),
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
post_dataList[position] = dataList[position] = et_dialog
.getText().toString();
mPublishListAdapter.notifyDataSetChanged();
}
});
builder.setNegativeButton(getResources().getString(R.string.txt_cancel),
null);
builder.show();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: