zoukankan      html  css  js  c++  java
  • 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();
    	}




  • 相关阅读:
    学会用好 Visual Studio Code
    Alpha冲刺阶段博客汇总
    第二天敏捷冲刺
    第一天敏捷冲刺
    需求分析与设计
    软工网络15团队作业2——团队计划
    团队组队&灰化肥挥发会发黑
    Tomcat安装及部署
    正则表达式
    爬取腾讯疫情数据
  • 原文地址:https://www.cnblogs.com/jinfenglee/p/4388725.html
Copyright © 2011-2022 走看看