應用的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)應該就沒問題了