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