1.
Develop a program to implement custom toast alert
[Link] :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Java file :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Button button = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link], "Hello, this is a toast!", Toast.LENGTH_SHORT).show();
}
});
}
}
[Link] a program to create an activity using Log.d
What Is Log.d() in Android?
Log.d() is used to print debug messages to the Logcat window in Android Studio.
It's very useful when you're developing apps and want to check what's happening in your code — like
when a button is clicked or when an activity starts.
XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="@+id/logButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>
Java file :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
// Tag used for logging
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Log.d(TAG, "onCreate: Activity created"); // Log when activity is created
Button logButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View view) {
Log.d(TAG, "Button clicked!"); // Log on button click
}
});
}
}
[Link] a program to implement new activity using explicit intent and implicit intent.
xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Start Dialer" />
</LinearLayout>
Java file :
package [Link].exp3;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
{
Button b1;
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
b1=findViewById([Link].btn1);
[Link](new [Link]()
{
public void onClick(View v)
{
Intent i=new Intent(Intent.ACTION_VIEW);
[Link]([Link]("Tel :"));
startActivity(i);
}
});
}
}
[Link] a program AutocompleteTextview.
Xml file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<AutoCompleteTextView
android:id="@+id/a1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Select Subject"
android:completionThreshold="1"/>
</RelativeLayout>
Java file :
package [Link].pdf1;
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
{
private AutoCompleteTextView ac;
private String[] subjects={"Android","Python","PHP","ETI","EDE","Management"};
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
ac=findViewById([Link].a1);
ArrayAdapter<String> adapter=new ArrayAdapter<>
(this, [Link].simple_dropdown_item_1line,subjects);
[Link](adapter);
}
}
[Link] a program to implement sensors.
[Link] a program to build a camera.
[Link] program for Broadcasr receiver
[Link] program for Radiogroup
Xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Single Radio Buttons"
android:textSize="20dp"/>
<RadioButton
android:id="@+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton 1"
android:checked="false"
android:textSize="20dp"/>
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RadioButton 2"
android:checked="false"
android:textSize="20dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button inside RadioGroup"
android:textSize="20dp"/>
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Female"
android:textSize="20dp"/>
<RadioButton
android:id="@+id/radioButton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Male"
android:textSize="20dp"/>
<Button
android:id="@+id/button2"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20dp"/>
</RadioGroup>
</LinearLayout>
Java file :
package [Link].pdf1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
{
RadioButton rb;
RadioGroup rg;
Button b;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
b=findViewById([Link].button2);
rg=findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View view) {
int selected=[Link]();
if(selected!=1)
{
rb=findViewById(selected);
[Link](getApplicationContext(),[Link](),Toast.LENGTH_LONG).show();
}
else
{
[Link](getApplicationContext(),"Please select an
Option",Toast.LENGTH_LONG).show();
}
}
});
}
}
[Link] a program for Bluetooth connectivity.
[Link] a program for checkbox.
Xml file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Subjects : "
android:textSize="25dp"/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MAD"
android:layout_marginTop="30dp"
android:textSize="20dp"/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MGT"
android:layout_marginTop="60dp"
android:textSize="20dp"/>
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WBP"
android:layout_marginTop="90dp"
android:textSize="20dp"/>
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PWP"
android:layout_marginTop="120dp"
android:textSize="20dp"/>
<CheckBox
android:id="@+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ETI"
android:layout_marginTop="150dp"
android:textSize="20dp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
android:layout_marginTop="200dp"
android:textSize="20dp"/>
</RelativeLayout>
Java file :
package [Link].exp10;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
CheckBox c1, c2, c3, c4, c5;
Button b1;
String s;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
c1=(CheckBox) findViewById([Link].checkBox1);
c2=(CheckBox) findViewById([Link].checkBox2);
c3=(CheckBox) findViewById([Link].checkBox3);
c4=(CheckBox) findViewById([Link].checkBox4);
c5=(CheckBox) findViewById([Link].checkBox5);
b1=(Button) findViewById([Link]);
[Link](new [Link]() {
public void onClick(View view) {
s=" ";
if([Link]())
s=s+[Link]().toString()+"\n";
if([Link]())
s=s+[Link]().toString()+"\n";
if([Link]())
s=s+[Link]().toString()+"\n";
if([Link]())
s=s+[Link]().toString()+"\n";
if([Link]())
s=s+[Link]().toString()+"\n";
}
[Link](getApplicationContext(),"Selected Subjects : \
n"+s,Toast.LENGTH_LONG).show();
});
[Link] a program for ListView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
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="match_parent" />
</LinearLayout>
Java file :
package [Link].exp11;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
ListView l;
static final String[] city=new String[]{"Android","Java","Hadoop","Sap","Python","Ajax","C+
+","Ruby","Rails"};
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
l=(ListView) findViewById([Link]);
ArrayAdapter adapter=new
ArrayAdapter<String>(this,[Link].support_simple_spinner_dropdown_item,city);
[Link](adapter);
[Link](new [Link]() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
[Link]([Link],((TextView)view).getText(),Toast.LENGTH_LONG).show();
});
[Link] a program to display circular progressbar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show" />
</LinearLayout>
Java file :
package [Link].exp12;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
ProgressBar p;
Button b;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
p=findViewById([Link]);
b=findViewById([Link]);
[Link](View::invalidate);
[Link]([Link]);
[Link] a program for Toggle Button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Bluetooth is OFF"
android:textOn="Bluetooth is ON"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:layout_marginTop="60sp"/>
</RelativeLayout>
Java file :
package [Link].exp13;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
ToggleButton t;
Button btn;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
t=(ToggleButton) findViewById([Link]);
btn=(Button) findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View view) {
if([Link]())
[Link](getApplicationContext(),"Bluetooth is ON",Toast.LENGTH_LONG).show();
else
[Link](getApplicationContext(),"Bluetooth is OFF",Toast.LENGTH_LONG).show();
}
});
[Link] a program for Gridview.
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<GridView
android:id="@+id/g"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="100dp"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
</[Link]>
Java file :
package [Link].exp14;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
protected void onCreate(Bundle savedInstanceState)
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
GridView gv=findViewById([Link].g);
String[] labels=new String[15];
for(int i=0;i<15;i++)
labels[i] = "Button" + (i + 1);
ArrayAdapter<String>adapter=new ArrayAdapter<>(this,
[Link].simple_list_item_1,labels);
[Link](adapter);
[Link](new [Link]()
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String buttonlabel=((String)[Link](position));
[Link]([Link],buttonlabel+"Clicked",Toast.LENGTH_LONG).show();
});
}
1)Write a program to display following output using suitable layout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:background="#e0f0ff"
android:padding="16dp">
<!-- Row 1 -->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Row1"
android:background="#007bff"
android:textColor="#fff"
android:layout_marginBottom="16dp" />
<!-- Row 2 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginBottom="16dp">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Row2\nCol1"
android:background="#007bff"
android:textColor="#fff"
android:layout_marginEnd="8dp"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Row2\nCol2"
android:background="#007bff"
android:textColor="#fff" />
</LinearLayout>
<!-- Row 3 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:layout_marginBottom="16dp">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Row3\nCol1"
android:background="#007bff"
android:textColor="#fff"
android:layout_marginEnd="8dp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Row3\nCol2"
android:background="#007bff"
android:textColor="#fff"
android:layout_marginEnd="8dp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Row3\nCol3"
android:background="#007bff"
android:textColor="#fff" />
</LinearLayout>
<!-- Row 4 -->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Row4"
android:background="#007bff"
android:textColor="#fff" />
</LinearLayout>
</ScrollView>
2) Develop the registration form using the following GUI.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/white"
android:padding="20dp"
android:gravity="center_horizontal"
android:elevation="4dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginHorizontal="8dp">
<!-- Header Image -->
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/sample_image"
android:layout_gravity="center"
android:layout_marginBottom="24dp"
android:scaleType="centerCrop" />
<!-- Name -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:padding="12dp"
android:layout_marginBottom="12dp" />
<!-- Email -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email ID"
android:inputType="textEmailAddress"
android:padding="12dp"
android:layout_marginBottom="12dp" />
<!-- Password -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:padding="12dp"
android:layout_marginBottom="12dp" />
<!-- Confirm Password -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Confirm password"
android:inputType="textPassword"
android:padding="12dp"
android:layout_marginBottom="12dp" />
<!-- Mobile -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Mobile"
android:inputType="phone"
android:padding="12dp"
android:layout_marginBottom="12dp" />
<!-- Gender -->
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="20dp">
<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_marginStart="20dp" />
</RadioGroup>
<!-- Register Button -->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register"
android:backgroundTint="#03A9F4"
android:textColor="#ffffff" />
</LinearLayout>
</ScrollView>