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

对于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();
	}




转载于:https://www.cnblogs.com/jinfenglee/p/4388725.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值