Answer the question
In order to leave comments, you need to log in
Android. How to correctly implement the change of content on the screen?
Now I use the following code to show progress, error block and main content:
private void showError(@Nullable String error, @Nullable View.OnClickListener buttonListener) {
if (error != null) errorMessage.setText(error);
errorButton.setOnClickListener(buttonListener);
content.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.INVISIBLE);
errorBlock.setVisibility(View.VISIBLE);
}
private void showContent() {
content.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.INVISIBLE);
errorBlock.setVisibility(View.INVISIBLE);
}
private void showProgress() {
content.setVisibility(View.INVISIBLE);
progressBar.setVisibility(View.VISIBLE);
errorBlock.setVisibility(View.INVISIBLE);
}
Answer the question
In order to leave comments, you need to log in
There is no universal and "correct" solution for your task, it all depends on the UI and business logic of the application. For simple Views, your solution works just fine. The only thing is that you can use View.GONE instead of View.INVISIBLE so that invisible Views do not participate in the process of measuring the container.
If you have a complex UI for errorBlock, let's say it's a form for sending an error message by email or something like that, then you can think about a separate fragment for errorBlock.
Well, that just doesn't mean it's bad!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question