问题描述
- 辅助类中的View.VISIBLE 和View.INVISIBLE
- 应用的Activity中有一个布局文件和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
中激活progressbar
,不知道怎么做? 现在的出现空指针,我知道不能从这里访问UI:public InternetHelper (Context context) { myContext = context; }public void ShowProgressBar(boolean show){ if (show){pleasewait.setVisibility(View.VISIBLE);}else{pleasewait.setVisibility(View.INVISIBLE);}}
解决方案
在helperclass中:
ProgressBar myBar;public InternetHelper (Context context ProgressBar pleasewait) { myContext = context; myBar = pleasewait; }
再用ShowProgressBar(boolean)应该就没问题了
时间: 2024-10-27 02:18:21