Pop-up does not dismiss

↘锁芯ラ 提交于 2019-12-11 21:46:51

问题


I have a EditText view,

<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 pop-up window which opens when the user touches this EditText view. This pop-up window has a button, so when clicked pop-up supposed to be dismissed. Although it gets my clicks, the pop-up does not close. Here is my pop-up 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?


回答1:


I use following code to start a custom dialog which is similar to PopUp. If you need I can share the layout file as well. dialog.cancel(); is also similar to dismiss.

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's time to show it    
    dialog.show();  
}



回答2:


The problem was; I was using onTouchListener for the EditText. As dmon , stated in the answer for the similar problem, onTouchListener responds for both landing and lifting. So when I changed it to onClickListener the problem solved.



来源:https://stackoverflow.com/questions/9833298/pop-up-does-not-dismiss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!