Popup does not cancel

I have an idea EditText,

<EditText
android:layout_weight="1"
android:id="@+id/etMiktar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/miktarHint"
android:focusable="false">
</EditText>

And I implemented a popup that opens when the user touches this kind of EditText. There is a button in this popup, so when clicked, the popup should be fired. Although it gets my clicks, the popup does not close. Here is my popup implementation:

private void inflatePopUpSiparis(){
    LayoutInflater inflater = (LayoutInflater)
    this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final PopupWindow pwSiparis = new PopupWindow(inflater.inflate(R.layout.siparismiktarpopup, null, false),400,550,true);         
    pwSiparis.showAtLocation(this.findViewById(R.id.llMain), Gravity.CENTER, 0, 0);
    //pwSiparis.setFocusable(true);
    View myPopUpSiparisView = pwSiparis.getContentView();

    etSiparisMiktar=(EditText)myPopUpSiparisView.findViewById(R.id.etSiparisMiktar);
    etSiparisMiktar.setText(etUrunMiktar.getText().toString());

    btnPopUpSiparisTamam=(Button)myPopUpSiparisView.findViewById(R.id.btnPopUpSiparis);
    btnPopUpSiparisTamam.setOnClickListener(new OnClickListener() { 
        public void onClick(View v) {
            pwSiparis.dismiss();
            Log.d("****",etSiparisMiktar.getText().toString().toString());
            etUrunMiktar.setText(etSiparisMiktar.getText().toString());
      }
    });


}

}

What could be the problem?

0
source share
2 answers

The problem was; I used onTouchListener for EditText. Like the dmon provided in the answer for a similar problem, onTouchListener is responsible for both landing and lifting. So when I changed it to onClickListener, the problem is resolved.

0
source

, , PopUp. , . dialog.cancel(); .

private void showpopup(int popuptype, String message) {

    //set up dialog
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog);

    //dialog.setTitle("This is my custom dialog box");
    dialog.setCancelable(true);
    //there are a lot of settings, for dialog, check them all out!

    //set up text
    TextView text = (TextView) dialog.findViewById(R.id.textViewSubject);
    text.setText(message);       

    //set up button
    Button button = (Button) dialog.findViewById(R.id.buttonOK);
    button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Log.e("Alert", "Nothing");
            dialog.dismiss();
        }
    });
    //now that the dialog is set up, it time to show it    
    dialog.show();  
}
0

All Articles