Android 自定义AlertDialog并通过AlertDialog修改TextView的值

点击按钮“E”跳出AlertDialog进行TextView的修改:

button_edit.setOnClickListener(new View.OnClickListener() {
			
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final View view = layoutInflater.inflate(R.layout.layout_editdialog, null);
		AlertDialog alertDialog = new AlertDialog.Builder(CallActivity.this)
		.setTitle(getResources().getString(R.string.dialog_title))
		.setView(view)
		.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
					
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				EditText mEditText = (EditText)view.findViewById(R.id.editText_editname);
				String newName = mEditText.getText().toString();
				//这里就获取到了修改到的值,剩下的就是把这个newName用TextView的setText方法放入
			}
		}).setNegativeButton(getResources().getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
	
			@Override
			public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			dialog.dismiss();
		}
	}).create();		
	alertDialog.show();
	}
});



你可能感兴趣的:(Android)