android popwindow输入框与返回键焦点冲突问题

创建一个popwindow 弹出一个页面 里面有输入框 如果输入框没有获取焦点点击系统返回键能监听到点击了返回按钮 但是输入框获取焦点后 就监听不到系统返回键了 请大神指教 贴一点核心代码
View popupWindow_view = getLayoutInflater().inflate(R.layout.mydialog_myprice, null, false);
popupWindow = new PopupWindow(popupWindow_view, LayoutParams.MATCH_PARENT,mScreenHight, true);
popupWindow.setFocusable(true);
popupWindow.setAnimationStyle(R.style.popupWindowAnimation);
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//设置动画
WindowManager.LayoutParams params=DetailsPurchaseActivity.this.getWindow().getAttributes();

params.alpha=0.3f;
DetailsPurchaseActivity.this.getWindow().setAttributes(params);
//设置窗口焦点
//设置返回键能够监听事件

popupWindow_view.setFocusable(true);
popupWindow_view.setFocusableInTouchMode(true);
popupWindow_view.setOnKeyListener(new OnKeyListener() {

1个回答

final AlertDialog dlg = new AlertDialog.Builder(context).create();
dlg.show();
Window window = dlg.getWindow();
window.setContentView(R.layout.dialog_alter_name);
window.setGravity(Gravity.CENTER);
editText = (EditText) window.findViewById(R.id.edit_name);
editTextNumber = (EditText) window.findViewById(R.id.edit_number);
editText.setText(datas.get(position).getName());
editTextNumber.setText(datas.get(position).getPhone());
Button ok = (Button) window.findViewById(R.id.ok);
Button cancle = (Button) window.findViewById(R.id.cancel);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!editText.getText().toString().equals("")) {
datas.get(position).setName(editText.getText().toString());
if (!editTextNumber.getText().toString().equals("")) {
datas.get(position).setPhone(editTextNumber.getText().toString());
}
notifyDataSetChanged();
}
dlg.dismiss();
}
});
cancle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dlg.dismiss();
}
});

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问