Do i need to create another activity just to show little bit of information? (Android) (Java)

Viewed 75

Hi I'm an android beginner just figuring things out,

and now I'm stuck for a couple of days figuring out how to create 1 activity and change its content based on what button the user selects.

So I'm building a small project which is a first aid application where there are at least 15-25 list of buttons that will display different kinds of first aid tutorials. what is the best way to implement this?

so far I've managed to create a list of buttons that directs users to another activity list of buttons.

After clicking the burns button, these steps will pop up and each of them was clickable and will direct the user to another activity which will elaborate that steps with image and video After clicking the burns button

I've already tried to use 1 activity and send information using intent.putExtra() however the problem is I can't change the button destination of each step (the elaboration part) it changed the information for each step but when it's clicked. It just leads me to the same elaboration part for (burns step).

I am sure there are better ways of implementing this, instead of creating another activity for every button clicked just show little information. any help will be very much appreciated please note that I am really just a beginner, an informative explanation will genuinely help me a lot thankyou.

Code (list_of_firstAid.java):

  buttonBurns.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), burnsActivity.class);

            intent.putExtra("procedure_1", getResources().getString(R.string.burns_procedure_1));
            intent.putExtra("procedure_2", getResources().getString(R.string.burns_procedure_2));
            intent.putExtra("procedure_3", getResources().getString(R.string.burns_procedure_3));
            intent.putExtra("procedure_4", getResources().getString(R.string.burns_procedure_4));
            intent.putExtra("procedure_5", getResources().getString(R.string.burns_procedure_5));
            intent.putExtra("note_procedure_1", getResources().getString(R.string.burns_note_1));

            startActivity(intent);
        }
    });

Code: (burnsActivity.java)

public void process(View view){
    if(view.getId() == R.id.burnsStep1)
    {
        Intent intent = new Intent(burnsActivity.this, displayInfoActivity.class);
        intent.putExtra("step_1", getResources().getString(R.string.firstaid_burnsactivity_information_number_1_bullet_1));
        intent.putExtra("image_1", R.drawable.round_bk2);
        intent.putExtra("step_2", "this is step 2");
        startActivity(intent);
    }
    else if(view.getId() == R.id.burnsStep2)
    {
        Intent intent = new Intent(burnsActivity.this, displayInfoActivity.class);
        intent.putExtra("step_1", getResources().getString(R.string.firstaid_burnsactivity_information_number_2_bullet_1));
        intent.putExtra("image_1", R.drawable.round_bk3);
        intent.putExtra("step_2", "");
        startActivity(intent);
    }
    else if (view.getId() == R.id.burnsStep3)
    {
        Intent intent = new Intent(burnsActivity.this, displayInfoActivity.class);
        intent.putExtra("step_1", getResources().getString(R.string.firstaid_burnsactivity_information_number_3_bullet_1));
        intent.putExtra("image_1", R.drawable.round_bk5);
        intent.putExtra("step_2", getResources().getString(R.string.firstaid_burnsactivity_information_number_3_bullet_2));
        startActivity(intent);
    }
    else if (view.getId() == R.id.burnsStep4)
    {
        Intent intent = new Intent(burnsActivity.this, displayInfoActivity.class);
        intent.putExtra("step_1", getResources().getString(R.string.firstaid_burnsactivity_information_number_4_bullet_1));
        intent.putExtra("image_1", R.drawable.round_bk5);
        intent.putExtra("step_2", getResources().getString(R.string.firstaid_burnsactivity_information_number_4_bullet_2));
        startActivity(intent);
    }
    else if (view.getId() == R.id.burnsStep5)
    {
        Intent intent = new Intent(burnsActivity.this, displayInfoActivity.class);
        intent.putExtra("step_1", getResources().getString(R.string.firstaid_burnsactivity_information_number_5_bullet_1));
        intent.putExtra("image_1", R.drawable.round_bk5);
        intent.putExtra("step_2", getResources().getString(R.string.firstaid_burnsactivity_information_number_5_bullet_2));
        startActivity(intent);
    }
    else if (view.getId() == R.id.burnsNote1)
    {
        Intent intent = new Intent(burnsActivity.this, displayInfoActivity.class);
        intent.putExtra("step_1", getResources().getString(R.string.firstaid_burnsactivity_information_number_6_bullet_1));
        intent.putExtra("image_1", R.drawable.round_bk5);
        intent.putExtra("step_2", getResources().getString(R.string.firstaid_burnsactivity_information_number_6_bullet_2));
        startActivity(intent);
    }

EDIT: The above code will change the information of each of these steps. however, these steps are also clickable. so when I reuse this activity for bleeding (for example) and change the text of each step it works but when its clicked it shows the same information I put on burnsActivity. enter image description here

1 Answers

I am also a beginner Android Developer and I have worked on an app which is quite similar to yours.

Structure

You should separate your project in Model, View and Controller layers to make it easier to develop and maintain.


Model

Model consists of two classes named AidTool and AidBox.

AidTool- It represents a single aid tool. It should contain name of the tool and its tutorial. Assign each tool with an UID which will help you later.

AidBox- It stores of all the aid tools in an ArrayList. It should contain methods to retrieve any tool.


View

View consists of a single activity ToolList which will display each aid tool. I suggest you use RecyclerView to display name of each aid tool and also handle any click events on them.


Controller

Controller consists of a single activity ToolTutorial. On clicking any aid tool on the ToolList, start the activity ToolTutorial. It should use an extra named tool UID which will be used to display tool tutorial.


I have not given a lot of details. I have just provided an overall structure of the app. Using the model layer, you can just use a single activity to display tutorial of any aid tool. You should also look into singletons. It might help you in your application if you use this structure.

I hope I have helped you.

Related