In Android, is there a way to require the user to select an option from the popup menu? I don't want to use a dialog fragment because I think it would be too obstructive. So if they click outside of the popup menu, the menu should still stay there, until they select an option.
public void showPopup(View view){
autonButton = (ToggleButton)view;
pw = new PopupWindow(getApplicationContext());
pw.setTouchable(true);
pw.setFocusable(true);
pw.setOutsideTouchable(true);
pw.setTouchInterceptor(new OnTouchListener(){
public boolean onTouch(View v, MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_OUTSIDE)
{
//pw.dismiss();
Log.d("popup window", "popup outside");
return false;
}
else if(event.getAction() == MotionEvent.ACTION_DOWN)
Log.d("popup window", "popup down");
return true;//if I put true here, the entire screen freezes, and i can't get any input
}
});
pw.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
pw.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
pw.setOutsideTouchable(false);
pw.setContentView(autonPopup);
pw.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
pw.showAsDropDown(view, 0, 0);
View popupView = pw.getContentView();
optionR = (Button) popupView.findViewById(R.id.auton_select1);
optionR.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
autonButton.setChecked(true);
autonButton.setText("Red");
}
});
optionB = (Button) autonPopup.findViewById(R.id.auton_select2);
optionB.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
autonButton.setChecked(true);
autonButton.setText(" Blue");
}
});
}