Search code examples
androidandroid-layoutandroid-fragmentslayout-inflater

Programmatically show Layout to preface an activity


What I want to do:

I want to have multiple activities each prefaced with a page explaining to the user what the activity is about.

What I'm currently doing:

So my main class BaseModuleActivity extends Activity and I am trying to write a function called showTutorial() which will explain the next steps to the users.

Here is my attempt in doing so:

public void showTutorial(String title, String explanation){
               setContentView(R.layout.tutorial_screen);
        TextView tv1 = (TextView)findViewById(R.id.tutoTextTitle);
        tv1.setText(title);

        TextView tv2 = (TextView)findViewById(R.id.tutoTextExplanation);
        tv2.setText(explanation);

        findViewById(R.id.tutoButton).setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
                //remove the tutorial's view
                findViewById(R.id.tutoLayout).setVisibility(View.GONE);
            }
        });
    }

And this method is called in the following:

public class myFirstActivity extends BaseModuleActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_first);

        //First show tuto
        super.showTutorial(getString(R.string.upTitle),getString(R.string.upExplanation));

        //TODO then actually do the activity stuff
        /*
        (findViewById(R.id.next_button)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        */
    }
}

Problem:

I think the problem is mainly conceptual. I don't know the best approach to do this and the approach I'm taking is not working.

What I'm doing is not working because the view just become empty. I thought setting the visibility of the linearLayout to gone would make it disappear and the actual activity will able to take place.

What I need:

I need to understand if I can do what I want with my approach or not? Or what approach should I take.

I found some similar questions. However, the answer to these questions didn't seem to fit my problem.

I also looked into layout inflater and fragment, but layout inflater seem to be more for listView and fragment uses layout inflater.


Solution

  • Well, there are some approaches to show a guide for your activity (or application).
    First one, and probably the easiest, is to show a dialog/TextView when user enters an activity and explain the activity guide in that dialog/TextView using plain text. From your explanation, I think this one is what your are trying to do.
    Second one is to use something like slides with pictures to explain about your activity (like Google Sheets application).
    Third one is to explain each control in your activity separatly by highlighting them (similar to how Go Launcher explains its feature on first launch)

    You can find more info in below links:
    How to implement first launch tutorial like Android Lollipop apps: Like Sheets, Slides app?
    Android - first launch interactive tutorial