I inherit all of my activities and fragments from base activity and base fragment.
I want to centralize some behaviors across applications and create some separate git repositories for them.
A convention is that each activity and fragment should have a main ProgressBar
that is embedded inside XML layout anywhere, and its id is simply progress.
The problem is that the ProgressBar
class is defined in another git repository, while the actual XML is defined in other git repositories. Thus I have no access to R.id.progress
in my code.
In my BaseActivity
I have this code:
public class BaseActivity extends AppCompatActivity {
ProgressBar progress;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
progress = findViewById(R.id.progress); // this line is red
} catch (Exception ex) {
// notifying error
}
}
public void showProgress() {
// showing progress
}
public void hideProgress() {
// hiding
}
}
So that in all of my activities I simply call showProgress();
whenever I need to.
How should I solve this problem?