I want to make a class to process ProgressBar.
But i cant find a way to transfer the viewId, which make null pointer error.
This the helperclass:
public class HelperProgressBar {
ProgressBar progressBar;
Activity activity;
int ID;
public HelperProgressBar(Activity activity, int ID) {
this.activity = activity;
this.ID = ID;
progressBar.findViewById(ID);
}
public void showProgressBar(){
progressBar.setVisibility(View.VISIBLE);
activity.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
public void hideProgressBar(){
activity.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}}
And this how i call it:
HelperProgressBar helperProgressBar = new HelperProgressBar(getApplicationContext(), progressBar.getId());
2
Answers
because progressBar is in your parent layout, not in progressBar.
Just pass the view so that you can handle it.
The constructor does not assign
progressBar
, only callsprogressBar.findViewById(ID)