🔒 Closed Pahelp please mamakaawa me

Status
Not open for further replies.

LoliEffer

Leecher
Pahelp po please in android studio po please
Instructions:
Create an Android app project that has 2 text fields and 1 button. The button will compare the input from the text fields and display a response (SAME if values are the same and NOT THE SAME if they are not) if it is clicked.
 
Sure! Here are the steps to create an Android app project that has 2 text fields and 1 button, and compares the input from the text fields:

1. Open Android Studio and create a new project.
2. Choose "Empty Activity" as the template for your project.
3. Give your project a name and choose a location to save the project.
4. In the project window, open the "res" folder and then open the "layout" folder.
5. Click on "activity_main.xml" to open it in the editor.
6. In the "Palette" panel on the left side of the screen, drag two "EditText" components onto the layout.
7. Position them side-by-side so they are easy to see.
8. Drag a "Button" component onto the layout below the EditText components.
9. In the "Attributes" panel on the right side of the screen, modify the text of the EditText components and the Button component as desired.
10. Change the text of the button to "Compare".
11. In the "Attributes" panel, give both EditTexts an id. You can name them whatever you like. For this example, we'll use "editText1" and "editText2".
12. Next, add onClickListener for the button by adding the following code inside the onCreate method in the MainActivity.java file:

Code:
Button compareButton = (Button) findViewById(R.id.compare_button);

compareButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        String input1 = ((EditText) findViewById(R.id.editText1)).getText().toString();
        String input2 = ((EditText) findViewById(R.id.editText2)).getText().toString();

        if(input1.equals(input2)){
            Toast.makeText(MainActivity.this, "SAME", Toast.LENGTH_SHORT).show();
        }
        else{
            Toast.makeText(MainActivity.this, "NOT THE SAME", Toast.LENGTH_SHORT).show();
        }
    }
});

13. Run the app in an emulator or on a connected device.

Now, when you enter text into each EditText field and click the "Compare" button, the app will compare the two input values and display a toast message that says "SAME" if the input values are the same, or "NOT THE SAME" if they are not.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 513
    Views
  • 1
    Participants
Last reply from:
Unknown user

Online now

Members online
1,230
Guests online
2,040
Total visitors
3,270

Forum statistics

Threads
2,297,452
Posts
29,115,117
Members
1,203,892
Latest member
Dmoon
Back
Top