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.