dialog自动弹出软键盘、光标移至Edittext末尾

dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff"
    >

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/dialog_edittext" />
</LinearLayout>

实现代码:

AlertDialog.Builder builder;
builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.dialog, null);
final ClearEditText addHeader  = (ClearEditText) view.findViewById(R.id.dialog_edittext);
addHeader.setHint("添加Header");
addHeader.setText(Utils.getValue(getApplicationContext(),Constants.header));
//                addHeader.setText("378da32d78c444ce4da2f90ed529b436b8a28429");
builder.setTitle("添加头部:");
builder.setPositiveButton("确定",
        new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
builder.setNegativeButton("取消", null);
AlertDialog alertDialog = builder.create();
alertDialog.setView(view);
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
        //调出键盘
        InputMethodManager manager = ((InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE));
        manager.showSoftInput(addHeader,InputMethodManager.SHOW_IMPLICIT);
        //光标移至末尾处
        Selection.setSelection(addHeader.getText(), addHeader.length());
    }
});
alertDialog.show();