Android - 如果使用 setVisibility 如何完成按钮
我有按钮,它们都完成后进入下一个活动。
但我正在尝试完成一个具有 setVisibility 的按钮,如下面的示例代码。
Button failfiveButton = (Button)findViewById(R.id.failfive);
failfiveButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Button button = (Button) v;
button.setVisibility(View.INVISIBLE);
mSoundManager.playSound(2);
finish();
}
});
Button failsixButton = (Button)findViewById(R.id.failsix);
failsixButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Button button = (Button) v;
button.setVisibility(View.INVISIBLE);
mSoundManager.playSound(2);
finish();
}
});
因为上面的代码我有大约六个按钮,如果我添加 finish();
在mSoundManager.playSound(2);
下,它返回到第一个.主屏幕。而不是让我继续并让其余按钮不可见。
如果我没有完成();应用程序因内存泄漏过多而滞后。
谢谢
瓦希德
I have buttons and they all finish to go to the next activity.
But I'm trying to finish an button that has setVisibility like example code below.
Button failfiveButton = (Button)findViewById(R.id.failfive);
failfiveButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Button button = (Button) v;
button.setVisibility(View.INVISIBLE);
mSoundManager.playSound(2);
finish();
}
});
Button failsixButton = (Button)findViewById(R.id.failsix);
failsixButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Button button = (Button) v;
button.setVisibility(View.INVISIBLE);
mSoundManager.playSound(2);
finish();
}
});
Because I have about six buttons of the code above and if I add finish();
under mSoundManager.playSound(2);
it goes back to the first .main screen. Instead of letting me continue and make the rest of the buttons invisible.
If I don't finish(); the application lags from too much memory leaking.
Thanks
Wahid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之所以会发生这种情况,是因为单击按钮时就会调用此方法。它并不关心你点击了多少个按钮。在这里,您将完成每次单击按钮的活动,因此正在发生这种情况。一个愚蠢的解决方案可能是这样的
编辑:可能还有其他更好的方法来做到这一点。但我给了你这个解决方案,因为我不知道你的目的到底是什么。
Its happening because this method gets called when ever a button is clicked. it does't care how many buttons you click. here you are finishing your Activity for each button click, so this is happening. a silly solution could be this
Edit: there could be other better ways to do it. but i gave you this solution since i don't know what exactly is your purpose.