0% found this document useful (0 votes)
8 views69 pages

Unit 4

This document provides an overview of various user interface components in Android, including EditText, AutoCompleteTextView, Button, ImageButton, and ToggleButton. It explains their functionalities, usage, and how to implement them in an Android application with code examples. Additionally, it covers the importance of specifying input types for EditText and the role of listeners for button interactions.

Uploaded by

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

Unit 4

This document provides an overview of various user interface components in Android, including EditText, AutoCompleteTextView, Button, ImageButton, and ToggleButton. It explains their functionalities, usage, and how to implement them in an Android application with code examples. Additionally, it covers the importance of specifying input types for EditText and the role of listeners for button interactions.

Uploaded by

shrutimanval104
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

UNIT IV Designing User Interface(Weightage-6 marks)

Edit text
• EditText is a Widget of user interface (UI) used to retrieve and
modify text data from a user in an Android app.
• EditText is a subclass of TextView that inherit all the property of
TextView. Nowadays,
• EditText is represented with the PlainText element in UI, which
displays an empty text field while designing the app.
• EditText (or PlainText) is used in the app whenever you need input
from the user side and proceed with its text (or value) in your app.
• EditText (or PlainText) is not only used to get plain text in your
application, but even you can use it to get values such as email,
number, password, etc.
• To get the value of each type in EditText, you must specify its input
type in its inputType attribute. For example, to input plain text, set
the inputType attribute to "text", and to input only numeric values,
set the inputType attribute to "number".
<EditText
<?xml version="1.0" encoding="utf-8"?> android:id="@+id/editText2"
<RelativeLayout android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_alignParentStart="true"
xmlns:tools="http://schemas.android.com/tools" android:layout_alignParentTop="true"
android:layout_width="match_parent" android:layout_alignParentEnd="true"
android:layout_height="match_parent" android:layout_marginStart="105dp"
tools:context=".MainActivity" android:layout_marginTop="136dp"
tools:ignore="ExtraText"> android:layout_marginEnd="97dp"
android:ems="10"
<EditText android:inputType="textPassword"
android:id="@+id/editText1" android:hint="ereshmanter password"
android:layout_width="wrap_content" tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck"
android:layout_height="wrap_content" tools:layout_editor_absoluteX="84dp"
android:layout_alignParentTop="true" tools:layout_editor_absoluteY="127dp" />
android:layout_centerHorizontal="true" <Button
android:layout_marginTop="61dp" android:id="@+id/button"
android:ems="10" android:layout_width="wrap_content"
android:inputType="text" android:layout_height="wrap_content"
android:hint="enter text?" android:layout_below="@+id/editText2"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" android:layout_centerHorizontal="true"
tools:layout_editor_absoluteX="84dp" android:layout_marginTop="109dp"
tools:layout_editor_absoluteY="53dp" /> android:text="Show Value"
tools:layout_editor_absoluteX="148dp"
tools:layout_editor_absoluteY="266dp"
tools:ignore="HardcodedText" />
</RelativeLayout>
package com.example.myapplication_edittext; @Override
protected void onCreate(Bundle savedInstanceState) {
import android.os.Bundle; super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
import android.view.View;
setContentView(R.layout.activity_main);
import android.widget.Button;
import android.widget.EditText; addListenerOnButton();
import android.widget.Toast;
}
public void addListenerOnButton() {
import androidx.activity.EdgeToEdge; edittext1 = findViewById(R.id.editText1);
import androidx.appcompat.app.AppCompatActivity; edittext2 = findViewById(R.id.editText2);
import androidx.core.graphics.Insets; buttonDisplay = findViewById(R.id.button);
import androidx.core.view.ViewCompat;
buttonDisplay.setOnClickListener(new
import androidx.core.view.WindowInsetsCompat; View.OnClickListener() {
@Override
public class MainActivity extends AppCompatActivity { public void onClick(View view) {
String value1=edittext1.getText().toString();
private EditText edittext1, edittext2;
String value2=edittext2.getText().toString();
private Button buttonDisplay;
Toast.makeText(getApplicationContext(),value1+"\n"+value2,
Toast.LENGTH_LONG).show();
}
});
AutoCompleteTextView
• Android AutoCompleteTextView completes the word based
on the reserved words, so no need to write all the characters of
the word.
• Android AutoCompleteTextView is a editable text field, it
displays a list of suggestions in a drop down menu from which
user can select only one suggestion or value.
• Android AutoCompleteTextView is the subclass of EditText
class. The MultiAutoCompleteTextView is the subclass of
AutoCompleteTextView class.
<?xml version="1.0" encoding="utf-8"?> <AutoCompleteTextView
<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/autoCompleteTextView"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="200dp"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_marginStart="92dp"
xmlns:tools="http://schemas.android.com/tools" android:layout_marginTop="144dp"
android:text=""
android:id="@+id/main"
app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent" app:layout_constraintTop_toTopOf="parent" />
android:layout_height="match_parent"
</androidx.constraintlayout.widget.ConstraintLayout
tools:context=".MainActivity">
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What is your favourite programming
language?"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.032"
package com.example.myapplication_autocomplete_textview;
@Override
void onCreate(Bundle savedInstanceState) {
import android.graphics.Color; super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
import android.os.Bundle; setContentView(R.layout.activity_main);
import android.widget.ArrayAdapter; //Creating the instance of ArrayAdapter containing list of
import android.widget.AutoCompleteTextView; language names
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.select_dialog_item,language);
import androidx.activity.EdgeToEdge; //Getting the instance of AutoCompleteTextView
AutoCompleteTextView actv =
import androidx.appcompat.app.AppCompatActivity;
(AutoCompleteTextView)findViewById(R.id.autoCompleteTex
import androidx.core.graphics.Insets; iew);
import androidx.core.view.ViewCompat; actv.setThreshold(1);//will start working from first
character
import androidx.core.view.WindowInsetsCompat;
actv.setAdapter(adapter);//setting the adapter data into
the AutoCompleteTextView
public class MainActivity extends AppCompatActivity { actv.setTextColor(Color.RED);
}
String[] language }
={"C","C++","Java",".NET","iPhone","Android","ASP.NET","PHP"};
Button
• Android Button represents a push-button.
• The android.widget.Button is subclass of TextView class
and CompoundButton is the subclass of Button class.
• There are different types of buttons in android such as
RadioButton, ToggleButton, CompoundButton etc.
Android Button Example with Listener
• Here, we are going to create two textfields and one button for sum of two numbers.
• If user clicks button, sum of two input values is displayed on the Toast.
• We can perform action on button using different types such as calling listener on button or adding onClick
property of button in activity's xml file.
activity_main.xml <EditText
<?xml version="1.0" encoding="utf-8"?> android:id="@+id/editText2"
android:layout_width="wrap_content"
<RelativeLayout android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_below="@+id/editText1"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_centerHorizontal="true"
xmlns:tools="http://schemas.android.com/tools" android:layout_marginTop="32dp"
android:layout_width="match_parent" android:contentDescription="Enter a number2"
android:layout_height="match_parent" android:ems="10"
tools:context=".MainActivity"> android:hint="Number2"
android:inputType="number"
<EditText android:minHeight="48dp"
android:id="@id/editText1" tools:ignore="Autofill,LabelFor,EditableContentDescCheck"
android:layout_width="wrap_content" tools:layout_editor_absoluteX="84dp"
android:layout_height="wrap_content" tools:layout_editor_absoluteY="127dp" />
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" <Button
android:layout_marginTop="61dp" android:id="@+id/button"
android:contentDescription="Enter a number1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" android:layout_below="@+id/editText2"
android:hint="Number1" android:layout_centerHorizontal="true"
android:importantForAutofill="no" android:layout_marginTop="109dp"
android:inputType="number" android:text="ADD"
android:minHeight="48dp" tools:layout_editor_absoluteX="148dp"
tools:ignore="Autofill,LabelFor,EditableContentDescCheck" tools:layout_editor_absoluteY="266dp"
tools:layout_editor_absoluteX="84dp" tools:ignore="HardcodedText" />
tools:layout_editor_absoluteY="53dp" />
</RelativeLayout>
package com.example.myapplication_button;
public void addListenerOnButton() {
import android.os.Bundle;
edittext1 = (EditText) findViewById(R.id.editText1);
import android.view.View;
edittext2 = (EditText) findViewById(R.id.editText2);
import android.widget.Button;
buttonSum = (Button) findViewById(R.id.button);
import android.widget.EditText;
import android.widget.Toast;
buttonSum.setOnClickListener(new View.OnClickListener()
import androidx.activity.EdgeToEdge;
{
import androidx.appcompat.app.AppCompatActivity;
@Override
import androidx.core.graphics.Insets;
public void onClick(View view) {
import androidx.core.view.ViewCompat;
String value1=edittext1.getText().toString();
import androidx.core.view.WindowInsetsCompat;
String value2=edittext2.getText().toString();
int a=Integer.parseInt(value1);
public class MainActivity extends AppCompatActivity {
int b=Integer.parseInt(value2);
private EditText edittext1, edittext2;
int sum=a+b;
private Button buttonSum;
@Override
Toast.makeText(getApplicationContext(),String.valueOf(sum),
protected void onCreate(Bundle savedInstanceState) {
Toast.LENGTH_LONG).show();
super.onCreate(savedInstanceState);
}
setContentView(R.layout.activity_main);
});
}
addListenerOnButton();
}
}
ImageButton
• An ImageButton is an AbsoluteLayout which enables you to
specify the exact location of its children.
• This shows a button with an image (instead of text) that can be
pressed or clicked by the user.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main" <ImageButton
android:layout_width="match_parent" android:id="@+id/imageButton"
android:layout_height="match_parent" android:layout_width="wrap_content"
tools:context=".MainActivity"> android:layout_height="wrap_content"
<TextView android:layout_centerHorizontal="true"
android:layout_width="wrap_content" android:layout_centerVertical="true"
android:layout_height="wrap_content" android:src="@drawable/download"
android:layout_alignEnd="@+id/imageButton" app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentTop="true" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="140dp" app:layout_constraintHorizontal_bias="0.625"
android:text="Image Button" app:layout_constraintStart_toStartOf="parent"
android:textSize="30dp" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" tools:ignore="ContentDescription,MissingConstraints" />
app:layout_constraintHorizontal_bias="0.614" </androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText,MissingConstraints,SpUsage" />
package com.example.myapplication_imagebutton;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
ImageButton imgButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets; });
imgButton =(ImageButton)findViewById(R.id.imageButton);
imgButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Welcome to Android Image Button",Toast.LENGTH_LONG).show();
} });}}
Android ToggleButton
• Android Toggle Button can be used to display
checked/unchecked (On/Off) state on the button.
• It is beneficial if user have to change the setting between
two states. It can be used to On/Off Sound, Wifi, Bluetooth
etc.
• Since Android 4.0, there is another type of toggle button
called switch that provides slider control.
• Android ToggleButton and Switch both are the subclasses of
CompoundButton class.
<?xml version="1.0" encoding="utf-8"?>
<ToggleButton
<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/toggleButton2"
xmlns:android="http://schemas.android.com/apk/res/android android:layout_width="wrap_content"
" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:id="@+id/main" android:layout_marginTop="80dp"
android:layout_width="match_parent" android:text="ToggleButton"
android:textOff="Off"
android:layout_height="match_parent" android:textOn="On"
tools:context=".MainActivity"> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ToggleButton
android:id="@+id/toggleButton" <Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="8dp" android:layout_marginBottom="144dp"
android:layout_marginLeft="148dp"
android:layout_marginTop="80dp" android:text="Submit"
android:text="ToggleButton" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
android:textOff="Off"
android:textOn="On" </androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintEnd_toStartOf="@+id/toggleButton2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
package com.example.myapplication_toggle; addListenerOnButtonClick();
import android.os.Bundle; }
import android.view.View; public void addListenerOnButtonClick(){
import android.widget.Button;
//Getting the ToggleButton and Button instance from the layout xml
import android.widget.Toast; file
import android.widget.ToggleButton; toggleButton1=(ToggleButton)findViewById(R.id.toggleButton);
import androidx.activity.EdgeToEdge; toggleButton2=(ToggleButton)findViewById(R.id.toggleButton2);
import androidx.appcompat.app.AppCompatActivity;
buttonSubmit=(Button)findViewById(R.id.button);
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
//Performing action on button click
import androidx.core.view.WindowInsetsCompat;
buttonSubmit.setOnClickListener(new View.OnClickListener(){
public class MainActivity extends AppCompatActivity {
private ToggleButton toggleButton1, toggleButton2;
private Button buttonSubmit; @Override

@Override public void onClick(View view) {


protected void onCreate(Bundle savedInstanceState) { StringBuilder result = new StringBuilder();
super.onCreate(savedInstanceState); result.append("ToggleButton1 :
EdgeToEdge.enable(this);
").append(toggleButton1.getText());

setContentView(R.layout.activity_main); result.append("\nToggleButton2 :
").append(toggleButton2.getText());
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
//Displaying the message in toast
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
Toast.makeText(getApplicationContext(),
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
result.toString(),Toast.LENGTH_LONG).show();
return insets; });
}
Checkbox
• Android CheckBox is a type of two state button either checked or
unchecked.
• There can be a lot of usage of checkboxes. For example, it can be
used to know the hobby of the user, activate/deactivate the
specific action etc.
• Android CheckBox class is the subclass of CompoundButton
class.
• Android Checkbox class
• The android.widget.CheckBox class provides the facility of creating the
Checkboxess.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<CheckBox
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/checkBox3"
android:id="@+id/main" android:layout_width="wrap_content"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="match_parent" android:layout_marginLeft="144dp"
tools:context=".MainActivity">
android:layout_marginTop="28dp"
<CheckBox android:text="Burger"
android:id="@+id/checkBox" app:layout_constraintStart_toStartOf="parent"
android:layout_width="wrap_content" app:layout_constraintTop_toBottomOf="@+id/checkBox2"
android:layout_height="wrap_content" />
android:layout_marginLeft="144dp"
android:layout_marginTop="68dp" <Button
android:text="Pizza" android:id="@+id/button"
app:layout_constraintStart_toStartOf="parent" android:layout_width="wrap_content"
app:layout_constraintTop_toTopOf="parent" /> android:layout_height="wrap_content"
<CheckBox android:layout_marginLeft="144dp"
android:id="@+id/checkBox2"
android:layout_marginTop="184dp"
android:layout_width="wrap_content"
android:text="Order"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="144dp"
app:layout_constraintTop_toBottomOf="@+id/checkBox3"
android:layout_marginTop="28dp"
android:text="Coffee"
/>
app:layout_constraintStart_toStartOf="parent"
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
package com.example.myapplication_checkbox; public void addListenerOnButtonClick(){
import android.os.Bundle; //Getting instance of CheckBoxes and Button from the activty_main.xml file
import android.view.View; pizza=(CheckBox)findViewById(R.id.checkBox);
coffe=(CheckBox)findViewById(R.id.checkBox2);
import android.widget.Button; burger=(CheckBox)findViewById(R.id.checkBox3);
import android.widget.CheckBox; buttonOrder=(Button)findViewById(R.id.button);
import android.widget.Toast; //Applying the Listener on the Button click
buttonOrder.setOnClickListener(new View.OnClickListener(){
import androidx.activity.EdgeToEdge;
@Override
import androidx.appcompat.app.AppCompatActivity; public void onClick(View view) {
import androidx.core.graphics.Insets; int totalamount=0;
import androidx.core.view.ViewCompat; StringBuilder result=new StringBuilder();
result.append("Selected Items:");
import androidx.core.view.WindowInsetsCompat; if(pizza.isChecked()){
public class MainActivity extends AppCompatActivity { result.append("\nPizza 100Rs");
CheckBox pizza,coffe,burger; totalamount+=100;
}
Button buttonOrder; if(coffe.isChecked()){
@Override result.append("\nCoffe 50Rs");
protected void onCreate(Bundle savedInstanceState) { totalamount+=50;
}
super.onCreate(savedInstanceState);
if(burger.isChecked()){
EdgeToEdge.enable(this); result.append("\nBurger 120Rs");
setContentView(R.layout.activity_main); totalamount+=120;
}
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main) result.append("\nTotal: "+totalamount+"Rs");
, (v, insets) -> { //Displaying the message on the toast
Insets systemBars = Toast.makeText(getApplicationContext(), result.toString(),
insets.getInsets(WindowInsetsCompat.Type.systemBars()); Toast.LENGTH_LONG).show();
v.setPadding(systemBars.left, systemBars.top, systemBars.right, }
systemBars.bottom); });
return insets; }); addListenerOnButtonClick(); } }}
Android RadioButton

• RadioButton is a two states button which is either


checked or unchecked. If a single radio button is
unchecked, we can click it to make checked radio
button.
• Once a radio button is checked, it cannot be marked as
unchecked by user.
• RadioButton is generally used with RadioGroup.
RadioGroup contains several radio buttons, marking one
radio button as checked makes all other radio buttons
as unchecked.
<?xml version="1.0" encoding="utf-8"?>
<TextView
<LinearLayout android:id="@+id/textView2"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:layout_height="match_parent" android:textSize="22dp"
android:orientation="vertical" android:text="Radio button inside RadioGroup" />
tools:context=".MainActivity"> <!-- Customized RadioButtons -->
<TextView <RadioGroup
android:id="@+id/textView1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/radioGroup">
android:layout_height="wrap_content" <RadioButton
android:layout_marginTop="30dp" android:id="@+id/radioMale"
android:gravity="center_horizontal" android:layout_width="fill_parent"
android:textSize="22dp" android:layout_height="wrap_content"
android:text=" Male"
android:text="Single Radio Buttons" /> android:layout_marginTop="10dp"
<!-- Default RadioButtons --> android:checked="false"
<RadioButton android:textSize="20dp" />
android:id="@+id/radioButton1" <RadioButton
android:layout_width="fill_parent" android:id="@+id/radioFemale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:text=" Female"
android:text="Radio Button 1" android:layout_marginTop="20dp"
android:layout_marginTop="20dp" android:checked="false"
android:textSize="20dp" /> android:textSize="20dp" />
</RadioGroup>
<RadioButton
android:id="@+id/radioButton2" <Button
android:layout_width="fill_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Radio Button 2" android:text="Show Selected"
android:id="@+id/button"
android:layout_marginTop="10dp" android:onClick="onclickbuttonMethod"
android:textSize="20dp" /> android:layout_gravity="center_horizontal" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp" </LinearLayout>
android:layout_marginTop="20dp"
android:background="#B8B894" />
Button button;
package com.example.myapplication_radiobutton; RadioButton genderradioButton;
import android.os.Bundle; RadioGroup radioGroup;
@Override
import android.view.View; protected void onCreate(Bundle savedInstanceState) {
import android.widget.Button; super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
import android.widget.RadioButton; setContentView(R.layout.activity_main);
import android.widget.RadioGroup; radioGroup=(RadioGroup)findViewById(R.id.radioGroup);
}
import android.widget.Toast;
public void onclickbuttonMethod(View v){
int selectedId = radioGroup.getCheckedRadioButtonId();
import androidx.activity.EdgeToEdge; genderradioButton = (RadioButton) findViewById(selectedId);
import androidx.appcompat.app.AppCompatActivity; if(selectedId==-1){
Toast.makeText(MainActivity.this,"Nothing selected",
import androidx.core.graphics.Insets; Toast.LENGTH_SHORT).show();
import androidx.core.view.ViewCompat; }
else{
import androidx.core.view.WindowInsetsCompat; Toast.makeText(MainActivity.this,genderradioButton.getText(),
public class MainActivity extends AppCompatActivity { Toast.LENGTH_LONG).show();
}

}
}
Toast
• Andorid Toast can be used to display information for the
short period of time. A toast contains message to be
displayed quickly and disappears after sometime.
• The android.widget.Toast class is the subclass of
java.lang.Object class.
• You can also create custom toast as well for example
toast displaying image. You can visit next page to see
the code for custom toast.
• Toast class
• Toast class is used to show notification for a particular interval of
time.
• After sometime it disappears.
• It doesn't block the user interaction.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.myapplication_toast;
import android.os.Bundle;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v,
insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});

Toast.makeText(getApplicationContext(),"Hello
Javatpoint",Toast.LENGTH_SHORT).show();
Android ProgressBar
• Android progress bar dialog box to display the status
of work being done e.g. downloading file, analyzing
status of work etc.
• In this example, we are displaying the progress dialog
for dummy file download operation.
activity_main.xml

• <?xml version="1.0" encoding="utf-8"?>


• <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
• xmlns:app="http://schemas.android.com/apk/res-auto"
• xmlns:tools="http://schemas.android.com/tools"
• android:id="@+id/main"
• android:layout_width="match_parent"
• android:layout_height="match_parent"
• tools:context=".MainActivity">
• </androidx.constraintlayout.widget.ConstraintLayout>
@Override
MainActivity.java protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
package com.example.myapplication_progress_bar;
EdgeToEdge.enable(this);
import android.app.ProgressDialog; setContentView(R.layout.activity_main);
import android.os.Bundle; ProgressDialog progressBar = new ProgressDialog(this);
import android.os.Handler; progressBar.setCancelable(true);//you can cancel it by
pressing back button
import android.view.View;
progressBar.setMessage("File downloading ...");
import android.widget.Button; progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTA
import androidx.activity.EdgeToEdge; L); progressBar.setProgress(0);//initially progress is 0
import androidx.appcompat.app.AppCompatActivity; progressBar.setMax(100);//sets the maximum value 100
progressBar.show();//displays the progress bar
import androidx.core.graphics.Insets;
}
import androidx.core.view.ViewCompat; }
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity
{
Button btnStartProgress;
ProgressDialog progressBar;
ListView
• Android ListView is a view which contains the group of items and displays in a
scrollable list.
• ListView is implemented by importing android.widget.ListView class. ListView
is a default scrollable which does not use other scroll view.
• ListView uses Adapter classes which add the content from data source (such as
string array, array, database etc) to ListView.
• Adapter bridges data between an AdapterViews and other Views (ListView,
ScrollView etc).
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.myapplication_listview; @Override
import android.annotation.SuppressLint; protected void onCreate(Bundle savedInstanceState) {
import android.os.Bundle; super.onCreate(savedInstanceState);
import android.view.View; EdgeToEdge.enable(this);
import android.widget.AdapterView; setContentView(R.layout.activity_main);
import android.widget.ArrayAdapter; listView=(ListView)findViewById(R.id.listView);
import android.widget.ListView; listItem = getResources().getStringArray(R.array.array_technology);
import android.widget.TextView; final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
import android.widget.Toast;
android.R.layout.simple_list_item_1, android.R.id.text1, listItem);
listView.setAdapter(adapter);
import androidx.activity.EdgeToEdge;
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
Importandroidx.appcompat.app.AppCompatActivity;
@Override
import androidx.core.graphics.Insets;
public void onItemClick(AdapterView<?> adapterView, View view, int
import androidx.core.view.ViewCompat; position, long l) {
import androidx.core.view.WindowInsetsCompat; // TODO Auto-generated method stub
public class MainActivity extends AppCompatActivity String value=adapter.getItem(position);
{
Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show();
ListView listView;
}
TextView textView; });
String[] listItem; }
@SuppressLint("MissingInflatedId") }
Android ScrollView (Vertical)

• The android.widget.ScrollView class provides the


functionality of scroll view.
• ScrollView is used to scroll the child elements of palette
inside ScrollView.
• Android supports vertical scroll view as default scroll
view.
• Vertical ScrollView scrolls elements vertically.
• Android uses HorizontalScrollView for horizontal
ScrollView.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout <LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" >
xmlns:tools="http://schemas.android.com/tools" <Button
android:id="@+id/main" android:layout_width="fill_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="match_parent" android:text="Button 1" />
tools:context=".MainActivity"> <Button
<TextView android:layout_width="fill_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Button 2" />
android:textAppearance="?android:attr/textAppearanceMedium" <Button
android:text="Vertical ScrollView example" android:layout_width="fill_parent"
android:id="@+id/textView" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:text="Button 3" />
android:layout_centerHorizontal="true" <Button
android:layout_alignParentTop="true" android:layout_width="fill_parent"
tools:ignore="MissingConstraints" /> android:layout_height="wrap_content"
<ScrollView android:layout_marginTop="30dp" android:text="Button 4" />
android:layout_width="fill_parent" <Button
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:id="@+id/scrollView" android:layout_height="wrap_content"
tools:ignore="MissingConstraints"> android:text="Button 5" />
<Button
android:layout_width="fill_parent" <Button
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:text="Button 6" /> android:layout_height="wrap_content"
<Button android:text="Button 11" />
android:layout_width="fill_parent" <Button
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:text="Button 7" />
android:layout_height="wrap_content"
android:text="Button 12" />
<Button
<Button
android:layout_width="fill_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:text="Button 8" /> android:text="Button 13" />
<Button <Button
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Button 9" /> android:text="Button 14" />
<Button <Button android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Button 15" />
android:text="Button 10" />
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 16" />
ActivityMain.java
<Button
android:layout_width="fill_parent" package com.example.myapplication_scrollview;
android:layout_height="wrap_content"
android:text="Button 17" /> import android.os.Bundle;
<Button
android:layout_width="fill_parent" import androidx.activity.EdgeToEdge;
android:layout_height="wrap_content" import androidx.appcompat.app.AppCompatActivity;
android:text="Button 18" /> import androidx.core.graphics.Insets;
<Button import androidx.core.view.ViewCompat;
android:layout_width="fill_parent" import androidx.core.view.WindowInsetsCompat;
android:layout_height="wrap_content"
android:text="Button 19" /> public class MainActivity extends AppCompatActivity {
<Button
android:layout_width="fill_parent" @Override
android:layout_height="wrap_content" protected void onCreate(Bundle savedInstanceState) {
android:text="Button 20" /> super.onCreate(savedInstanceState);
</LinearLayout> EdgeToEdge.enable(this);
</ScrollView> setContentView(R.layout.activity_main);
</androidx.constraintlayout.widget.ConstraintLayout>
}
}
Android Custom Toast Example

• You are able to create custom toast in android. So, you


can display some images like congratulations or loss on
the toast. It means you are able to customize the toast
now.

activity_main.xml customtoast.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools" android:layout_height="match_parent"
android:id="@+id/custom_toast_layout"
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="match_parent" android:background="#F14E23">
android:layout_height="match_parent" <ImageView
tools:context=".MainActivity"> android:id="@+id/custom_toast_image"
<TextView android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:contentDescription="Hello world"
android:text="Hello World!" android:src="@drawable/download"
tools:ignore="HardcodedText" />
app:layout_constraintBottom_toBottomOf="parent"
<TextView
app:layout_constraintEnd_toEndOf="parent" android:id="@+id/custom_toast_message"
app:layout_constraintStart_toStartOf="parent" android:layout_width="wrap_content"
app:layout_constraintTop_toTopOf="parent" /> android:layout_height="wrap_content"
</androidx.constraintlayout.widget.ConstraintLayout> android:contentDescription="To"
android:text="JavaTpoint custom Toast"
tools:ignore="HardcodedText" />
</LinearLayout>
package com.example.myapplication_custom_toast; @Override
import android.annotation.SuppressLint;
protected void onCreate(Bundle savedInstanceState) {
import android.os.Bundle;
import android.view.Gravity; super.onCreate(savedInstanceState);
import android.view.LayoutInflater; EdgeToEdge.enable(this);
import android.view.View; setContentView(R.layout.activity_main);
import android.view.ViewGroup;
//Creating the LayoutInflater instance
import android.widget.Toast;
import androidx.activity.EdgeToEdge; LayoutInflater li = getLayoutInflater();
import androidx.appcompat.app.AppCompatActivity; //Getting the View object as defined in the customtoast.xml file
import androidx.core.graphics.Insets; @SuppressLint({"MissingInflatedId", "LocalSuppress"}) View layout =
import androidx.core.view.ViewCompat; li.inflate(R.layout.customtoast,(ViewGroup)
import androidx.core.view.WindowInsetsCompat; findViewById(R.id.custom_toast_layout));
public class MainActivity extends AppCompatActivity { //Creating the Toast object
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(layout);//setting the view of custom toast layout
toast.show();
}
}
DatePicker
• Android DatePicker is a widget to select date.
• It allows you to select date by day, month and year. Like DatePicker,
android also provides TimePicker to select time.
• The android.widget.DatePicker is the subclass of FrameLayout class.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <Button
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button1"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content"
xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_alignParentEnd="true"
android:layout_height="match_parent" android:layout_alignParentBottom="true"
tools:context=".MainActivity"> android:layout_marginEnd="140dp"
android:layout_marginBottom="129dp"
<TextView
android:text="Change Date"
android:id="@+id/textView1"
tools:ignore="HardcodedText" />
android:layout_width="wrap_content" <DatePicker
android:layout_height="wrap_content" android:id="@+id/datePicker"
android:layout_above="@+id/button1" android:layout_width="wrap_content"
android:layout_alignParentLeft="true" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_above="@+id/textView1"
android:layout_marginBottom="102dp" android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp" />
android:layout_marginLeft="30dp"
</RelativeLayout>
android:layout_marginStart="30dp"
android:text=""
tools:ignore="RtlHardcoded" />
package com.example.myapplication_date_picker;
import android.os.Bundle; @Override
import android.view.View;
public void onClick(View view) {
import android.widget.Button;
textview1.setText("Change Date: "+getCurrentDate());
import android.widget.DatePicker;
} });
import android.widget.TextView;
}
import androidx.activity.EdgeToEdge;
public String getCurrentDate(){
import androidx.appcompat.app.AppCompatActivity;
StringBuilder builder=new StringBuilder();;
import androidx.core.graphics.Insets;
builder.append((picker.getMonth() + 1)+"/");//month is 0 based
import androidx.core.view.ViewCompat;
builder.append(picker.getDayOfMonth()+"/");
import androidx.core.view.WindowInsetsCompat;
builder.append(picker.getYear());
public class MainActivity extends AppCompatActivity {
return builder.toString();
DatePicker picker;
}
Button displayDate;
}
TextView textview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
textview1=(TextView)findViewById(R.id.textView1);
picker=(DatePicker)findViewById(R.id.datePicker);
displayDate=(Button)findViewById(R.id.button1);
textview1.setText("Current Date: "+getCurrentDate());
displayDate.setOnClickListener(new View.OnClickListener(){
Android TimePicker
• Android TimePicker widget is used to select date.
• It allows you to select time by hour and minute.
• You cannot select time by seconds.
• The android.widget.TimePicker is the subclass of FrameLayout
class.
<?xml version="1.0" encoding="utf-8"?> <Button
<RelativeLayout android:id="@+id/button1"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools" android:layout_alignParentEnd="true"
android:layout_width="match_parent" android:layout_alignParentBottom="true"
android:layout_height="match_parent" android:layout_marginEnd="133dp"
tools:context=".MainActivity"> android:layout_marginBottom="88dp"
<TextView android:text="Change Time" />
android:id="@+id/textView1"
android:layout_width="wrap_content" <TimePicker
android:layout_height="wrap_content" android:id="@+id/timePicker"
android:layout_above="@+id/button1" android:layout_width="wrap_content"
android:layout_alignParentLeft="true" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_above="@+id/textView1"
android:layout_marginBottom="102dp" android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp" android:layout_marginBottom="36dp" />
android:layout_marginStart="30dp" </RelativeLayout>
android:text="" />
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
package com.example.myapplication_time_picker; EdgeToEdge.enable(this);
import android.os.Bundle; setContentView(R.layout.activity_main);
import android.view.View; textview1=(TextView)findViewById(R.id.textView1);
import android.widget.Button; timepicker=(TimePicker)findViewById(R.id.timePicker);
import android.widget.TextView; //Uncomment the below line of code for 24 hour view
import android.widget.TimePicker; timepicker.setIs24HourView(true);
import androidx.activity.EdgeToEdge; changetime=(Button)findViewById(R.id.button1);
import androidx.appcompat.app.AppCompatActivity; textview1.setText(getCurrentTime());
import androidx.core.graphics.Insets; changetime.setOnClickListener(new
import androidx.core.view.ViewCompat; View.OnClickListener(){
import androidx.core.view.WindowInsetsCompat; @Override
public class MainActivity extends AppCompatActivity { public void onClick(View view) {
TextView textview1; textview1.setText(getCurrentTime());
TimePicker timepicker; } }); }
Button changetime; public String getCurrentTime(){
String currentTime="Current Time:
"+timepicker.getCurrentHour()+":"+timepicker.getCurrentMinut
e();
return currentTime;
}
}
Create a login form with all necessary validations (On success
or unsuccessful login, display appropriate toast Message )
<?xml version="1.0" encoding="utf-8"?> <TextView
<RelativeLayout <EditText android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com android:layout_width = "wrap_content" android:layout_height="wrap_content"
/apk/res/android" android:layout_height = "48dp" android:text="Attempts Left:"
xmlns:app="http://schemas.android.com/apk/res-auto" android:id = "@+id/editText" android:id="@+id/textView2"
xmlns:tools="http://schemas.android.com/tools" android:hint = "Enter Name" android:layout_below="@+id/editText2"
android:id="@+id/main" android:focusable = "true" android:layout_alignParentLeft="true"
android:layout_width="match_parent" android:textColorHighlight = "#ff7eff15" android:layout_alignParentStart="true"
android:layout_height="match_parent" android:textColorHint = "#ffff25e6" android:textSize="25dp" />
tools:context=".MainActivity"> android:layout_marginTop = "46dp" <TextView
android:layout_below = "@+id/imageView" android:layout_width="wrap_content"
<TextView android:text = "Login" android:layout_alignParentLeft = "true" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_alignParentStart = "true" android:text="New Text"
android:layout_height = "wrap_content" android:layout_alignParentRight = "true" android:id="@+id/textView3"
android:id = "@+id/textview" android:layout_alignParentEnd = "true" android:layout_alignTop="@+id/textView2"
android:textSize = "35dp" tools:ignore="Autofill,HardcodedText,TextFields" /> android:layout_alignParentRight="true"
android:layout_alignParentTop = "true" android:layout_alignParentEnd="true"
android:layout_centerHorizontal = "true" <ImageView android:layout_alignBottom="@+id/textView2"
tools:ignore="HardcodedText,SpUsage" /> android:layout_width="wrap_content" android:layout_toEndOf="@+id/textview"
android:layout_height="wrap_content" android:textSize="25dp"
<TextView android:id="@+id/imageView" android:layout_toRightOf="@+id/textview"
android:layout_width = "wrap_content" android:src="@drawable/download" tools:ignore="RtlHardcoded" />
android:layout_height = "wrap_content" android:layout_below="@+id/textView" <Button
android:text = "Credentials" android:layout_centerHorizontal="true" /> android:layout_width="wrap_content"
android:id = "@+id/textView" android:layout_height="wrap_content"
android:layout_below = "@+id/textview" <EditText android:text="login"
android:layout_centerHorizontal = "true" android:layout_width="wrap_content" android:id="@+id/button"
android:textColor = "#ff7aff24" android:layout_height="48dp" android:layout_alignParentBottom="true"
android:textSize = "35dp" android:inputType="textPassword" android:layout_toLeftOf="@+id/textview"
tools:ignore="HardcodedText,SpUsage" /> android:ems="10" android:layout_toStartOf="@+id/textview" />
android:id="@+id/editText2" <Button
android:layout_below="@+id/editText" android:id="@+id/button2"
android:layout_alignParentLeft="true" android:layout_width="wrap_content"
android:layout_alignParentStart="true" android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText" android:layout_alignParentBottom="true"
android:layout_alignEnd="@+id/editText" android:layout_toEndOf="@+id/textview"
android:textColorHint="#ffff299f" android:layout_toRightOf="@+id/textview"
android:hint="Password" android:text="Cancel"
tools:ignore="Autofill" /> tools:layout_editor_absoluteX="160dp"
tools:layout_editor_absoluteY="258dp" />
</RelativeLayout>
package com.example.myapplication_loginform;
b1.setOnClickListener(new View.OnClickListener() {
import android.annotation.SuppressLint;
@SuppressLint("SetTextI18n")
import android.graphics.Color;
@Override
import android.os.Bundle;
public void onClick(View v) {
import android.view.View;
if(ed1.getText().toString().equals("admin") &&
import android.widget.Button;
ed2.getText().toString().equals("admin")) {
import android.widget.EditText;
Toast.makeText(getApplicationContext(),
import android.widget.TextView;
"Valid Credentials ....
import android.widget.Toast;
Redirecting...",Toast.LENGTH_SHORT).show();
import androidx.activity.EdgeToEdge;
}else{
import androidx.appcompat.app.AppCompatActivity;
Toast.makeText(getApplicationContext(), "Wrong
import androidx.core.graphics.Insets;
Credentials",Toast.LENGTH_SHORT).show();
import androidx.core.view.ViewCompat;
tx1.setVisibility(View.VISIBLE);
import androidx.core.view.WindowInsetsCompat;
tx1.setBackgroundColor(Color.RED);
public class MainActivity extends AppCompatActivity {
counter--;
Button b1,b2;
tx1.setText(Integer.toString(counter));
EditText ed1,ed2;
TextView tx1;
if (counter == 0) {
int counter = 3;
b1.setEnabled(false);
@Override
}
protected void onCreate(Bundle savedInstanceState) {
}
super.onCreate(savedInstanceState);
}
EdgeToEdge.enable(this);
});
setContentView(R.layout.activity_main);
b2.setOnClickListener(new View.OnClickListener() {
b1 = (Button)findViewById(R.id.button);
@Override
ed1 = (EditText)findViewById(R.id.editText);
public void onClick(View v) {
ed2 = (EditText)findViewById(R.id.editText2);
finish();
b2 = (Button)findViewById(R.id.button2);
}
tx1 = (TextView)findViewById(R.id.textView3);
});
tx1.setVisibility(View.GONE);
}
}

You might also like