1b) Create an application that takes the
name from a text box and shows a hello
message along with the name entered in
the text box, when the user clicks the
OK button.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidDomInspection -->
<LinearLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center">
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:hint="@string/enter_the_name"
android:inputType="text"
tools:ignore="TextFields" />
<Button
android:id="@+id/buttonGreet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Say_Hello" />
<TextView
android:id="@+id/textViewGreeting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp"
android:paddingTop="20dp"/>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText editTextName;
Button buttonGreet;
TextView textViewGreeting;
@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
editTextName = findViewById([Link]);
buttonGreet = findViewById([Link]);
textViewGreeting = findViewById([Link]);
[Link](this::onClick);
}
@SuppressLint("SetTextI18n")
private void onClick(View v) {
String name = [Link]().toString().trim();
[Link]("Hello " + name + "!");
}
}