은 내가 글고를 포함하는 PopupWindow를 만들고 다음 코드를 가지고 해제되지 않음 : 사용자가 윈도우 외부에 닿을 때 상자가 자동으로 해제해야 있도록안드로이드 PopupWindow는
lbs.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent arg1) {
int pWidth = 100;
int pHeight = 80;
int vHeight = mView.getHeight();
int[] location = new int[2];
v.getLocationOnScreen(location);
final View view = inflater.inflate(R.layout.list_popup, null, false);
final PopupWindow pw = new PopupWindow(view, pWidth, pHeight, false);
pw.setTouchable(true);
//pw.setFocusable(true);
pw.setOutsideTouchable(true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setContentView(view);
pw.showAtLocation(v, Gravity.NO_GRAVITY, location[0]-(pWidth/4), location[1]+vHeight);
//final LinearLayout layout = (LinearLayout)view.findViewById(R.id.PopupLayout);
final EditText input = (EditText)view.findViewById(R.id.Input);
input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
Log.i("Focus", "Focus Changed");
/*
if (hasFocus) {
InputMethodManager inputMgr = (InputMethodManager)myContext.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
inputMgr.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
}
*/
}
});
input.setText(lbs.getText().toString());
input.requestFocus();
pw.setOnDismissListener(new OnDismissListener(){
@Override
public void onDismiss() {
parentActivity.changeWeight(getId, Double.parseDouble(input.getText().toString()));
Log.i("View Visibility", "" + view.getVisibility());
}
});
pw.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
Log.i("Background", "Back Touched");
pw.dismiss();
return true;
}
return false;
}
});
return true;
}
});
PopupWindows는 setBackGroundDrawable 있습니다. Box 외부를 클릭하면 OnDismiss 메서드가 실행되기 때문에 상자가 닫히는 것을 알고 있습니다. 그러나 실제로 상자가 두 번 터치 될 때까지 사라지지 않습니다. onDismiss는 두 번 실행할 수 없기 때문에 사라집니다. 내가 여기서 무엇을 놓치고 있니?
편집 : 코드를 약간 업데이트했습니다. popupwindow에 포커스를 두지 않으면, 편집 텍스트에 초점을 맞추지 못하는 것을 제외하고는 모든 것이 완벽하게 작동합니다. 팝업에 setFocusable을하면 edittext는 즉시 포커스를 얻지 못하고 더블 클릭하여 제거해야합니다.
'pw.setFocusable (true);' –
이미 설정되었습니다. 나는 팝업에 초점을 맞춰야 만한다. 그렇지 않으면 내가 편집 텍스트에도 집중할 수 없다. 나는 실제로 결의안을 찾아 내 결과를 게시 할 것입니다. – ryandlf
정확히 내가 알고 싶은 것, 팝업 밖에서 클릭 이벤트를 처리하고 해산하는 방법. – anargund