【问题标题】:View.VISIBLE or View.INVISIBLE from helper class辅助类中的 View.VISIBLE 或 View.INVISIBLE
【发布时间】:2012-12-13 18:03:25
【问题描述】:

我有一个带有布局和 ProgressBar 的活动:

public class Saldo_Menu extends Activity implements OnClickListener, OnLongClickListener {

static InternetHelper IH;
ProgressBar pleasewait;  



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pleasewait=(ProgressBar)findViewById(R.id.pleasewait);

        IH=new InternetHelper(this);

        pleasewait.setVisibility(View.INVISIBLE);
}

我想从这个帮助类 InternetHelper 中激活进度条,谁能给我一个小例子。这给出了一个空指针,因为我知道我无法从那里访问 UI:

 public InternetHelper (Context context) {
        myContext = context;

         }

public void ShowProgressBar(boolean show){
 if (show){pleasewait.setVisibility(View.VISIBLE);}else{pleasewait.setVisibility(View.INVISIBLE);}
}

【问题讨论】:

    标签: android android-layout view progress-bar android-progressbar


    【解决方案1】:

    在帮助程序类中保存对进度条的引用,然后使用它来访问它。

    ProgressBar myBar;
    
    public InternetHelper (Context context, ProgressBar pleasewait) {
            myContext = context;
            myBar = pleasewait;
            }
    

    那么你应该可以毫无问题地使用你的ShowProgressBar(boolean)函数了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多