0% found this document useful (0 votes)
2 views3 pages

1bprogram_linearlayout

The document outlines the creation of an Android application that greets users by name. It includes the XML layout for the user interface, which consists of an EditText for name input, a Button to trigger the greeting, and a TextView to display the message. The Java code handles the button click event to retrieve the name and update the greeting message accordingly.

Uploaded by

23p61a6248
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

1bprogram_linearlayout

The document outlines the creation of an Android application that greets users by name. It includes the XML layout for the user interface, which consists of an EditText for name input, a Button to trigger the greeting, and a TextView to display the message. The Java code handles the button click event to retrieve the name and update the greeting message accordingly.

Uploaded by

23p61a6248
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

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 + "!");
}
}

You might also like