AlertDialog中使用自定义View,其中的Button如何设置点击事件监听

答:在点击事件前加上包名,否则总是被认作Dialog的点击事件而不是Button的点击事件!
 
public void showDialog(Context mContext) {
		LayoutInflater inflater = LayoutInflater.from(mContext);
		View view = inflater.inflate(R.layout.test, null); 
		
		AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
		builder.setTitle(R.string.test);
		builder.setView(view);
		builder.create();
		
		Button bt_test = (Button) view.findViewById(R.id.test);
		bt_test.setOnClickListener(new android.view.View.OnClickListener(){
			
			@Override
			public void onClick(View v) {
				Log.i("测试", "对话框中的Button被点击了");
			}
		});
		
		builder.show();
	}


 

你可能感兴趣的:(android,控件)