S
S
Sergey Semenko2016-05-31 21:26:02
Android
Sergey Semenko, 2016-05-31 21:26:02

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);
    }

But something tells me that it's better not to do this. How is this problem usually solved in "normal" applications?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
itdroid, 2016-05-31
@abler98

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 question

Ask a Question

731 491 924 answers to any question