[英]Activity Buttons still ACTIVE when replaced by Fragment
Basically, I want to open a fragment
from Activity
. 基本上,我想从
Activity
打开一个fragment
。 Everything worked fine (activity button opens the fragment and the fragment shows), until I miss-clicked outside the fragment's
layout where one of the Activity
button is located and it did its onClick
method. 一切正常(活动按钮打开了片段并显示了片段),直到我在
Activity
按钮之一所在的fragment's
布局之外单击Activity
右键,并且它执行了onClick
方法。 That's why I wondered why is my Activity
still active. 这就是为什么我想知道为什么我的
Activity
仍然活跃的原因。
this is how I open the fragment
from Activity
这是我从
Activity
打开fragment
I tried using .add
instead of .replace
still the same. 我尝试使用
.add
代替.replace
仍然相同。
@OnClick(R.id.login_register_lbl)
public void registerAction(View view) {
// TODO register transition...
FragmentManager fragmentManager = (LoginActivity.this.getFragmentManager());
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
RegisterFragment fragment = new RegisterFragment();
fragmentTransaction.replace(R.id.fragment_register_holder, fragment);
fragmentTransaction.commit();
}
在根元素集“ background”,“ clickable = true”&Focusable =“ true”中的片段布局中。
In my opinion you can achieve this functionality by 2 ways: 我认为您可以通过以下两种方法来实现此功能:
Open a dialog fragment in full screen mode to avoid accidentally clicks on activities views. 以全屏模式打开对话框片段,以避免意外单击活动视图。
If you wanted to show both fragment's and activity's views at the same time then, on click of your activity's button which opens the fragment, disable it by yourbutton.setenabled(false);
如果您想同时显示片段和活动的视图,则单击活动片段的按钮以打开片段,然后通过
yourbutton.setenabled(false);
将其禁用yourbutton.setenabled(false);
and when you wanted to close the fragment enable that button again. 当您要关闭片段时,请再次启用该按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.