skip to Main Content

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


  1. because progressBar is in your parent layout, not in progressBar.

    Just pass the view so that you can handle it.

    public HelperProgressBar(Activity activity, ProgressBar progressBar) {
        this.activity = activity;
        this.progressBar = progressBar;
    }
    
    Login or Signup to reply.
  2. The constructor does not assign progressBar, only calls progressBar.findViewById(ID)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search