[英]Pop-up does not dismiss
I have a EditText
view, 我有一个
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 pop-up window which opens when the user touches this EditText view. 我实现了一个弹出窗口,当用户触摸此EditText视图时会打开该窗口。 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? 可能是什么问题呢?
The problem was; 问题是; I was using onTouchListener for the EditText.
我在为EditText使用onTouchListener。 As dmon , stated in the answer for the similar problem, onTouchListener responds for both landing and lifting.
如dmon所示 ,对于类似问题, 答案是onTouchListener响应着陆和抬起。 So when I changed it to onClickListener the problem solved.
因此,当我将其更改为onClickListener时,问题解决了。
I use following code to start a custom dialog which is similar to PopUp. 我使用以下代码来启动类似于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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.