android 带EditView(编辑框)的AlertDialog(对话框)及获取输入内容

final EditText et = new EditText(this);
		  			
new AlertDialog.Builder(this).setTitle("搜索")
.setIcon(android.R.drawable.ic_dialog_info)
.setView(et)
.setPositiveButton("确定", new OnClickListener() {
	public void onClick(DialogInterface dialog, int which) {
	String input = et.getText().toString();
	if (input.equals("")) {
		Toast.makeText(getApplicationContext(), "搜索内容不能为空!" + input, Toast.LENGTH_LONG).show();
	}
	else {
		Intent intent = new Intent();
		intent.putExtra("content", input);
		intent.setClass(MainActivity.this, SearchActivity.class);
		startActivity(intent);
		}
	}
	})
.setNegativeButton("取消", null)
.show();

你可能感兴趣的:(android 带EditView(编辑框)的AlertDialog(对话框)及获取输入内容)