如果我在onClick()中调用一次它的方法,但是如果我在onClick()方法中调用它两次,它就不起作用了。
private void changeVisible() {
if(progressBar.getVisibility() == View.VISIBLE && loginButton.getVisibility() == View.GONE) {
progressBar.setVisibility(View.GONE);
loginButton.setVisibility(View.VISIBLE);
//Toast.makeText(this, "Button visible", Toast.LENGTH_LONG).show();
}
else {
progressBar.setVisibility(View.VISIBLE);
loginButton.setVisibility(View.GONE);
//Toast.makeText(this, "Button invisible", Toast.LENGTH_LONG).show();
}
}
用例:
@Override
public void onClick(View v) {
if (v.getId() == R.id.loginButton) {
changeVisible();
...
try {
...
if(...) {
...
}
else {
...
changeVisible();
}
}
catch(Exception e) {
...
changeVisible();
}
}
}
请帮忙。
答案 0 :(得分:0)
首先声明视图Globbaly
Progressbar pb;
Button button;
在你onCreate()
pb=(ProgressBar) findViewById(R.id.progressBar))
button = (Button) findViewById(R.id.loginButton);
方法
private void changeVisible() {
if(pb.getVisibility()==View.VISIBLE && button.getVisiblity()==View.GONE)
{
pb.setVisibility(View.GONE);
button.setVisibility(View.VISIBLE);
}
else
{
pb.setVisibility(View.VISIBLE);
button.setVisibility(View.GONE)
}
}