自定义AlertDialog,以及解决自定义Dialog中EditText不能弹出输入法的问题

private void showAlertDialog(final int position,String name,int count) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.shoppingcart_editcount, null);

final AlertDialog dialog = new AlertDialog.Builder(context).create();

//先设置一边setview(),可以解决edittext不能弹出输入法的问题

dialog.setView(view);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.shoppingcart_editcount);
TextView textview = (TextView) window
.findViewById(R.id.shoppingcart_editcount_productname_textview);
final EditText editText = (EditText) window
.findViewById(R.id.shoppingcart_editcount_count_edittext);
Button positiveButton = (Button) window
.findViewById(R.id.positiveButton);
Button negativeButton = (Button) window
.findViewById(R.id.negativeButton);

textview.setText(name);
editText.setHint(String.valueOf(count));
positiveButton.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {

}
});


negativeButton.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {

}
});
}

你可能感兴趣的:(android)