0% found this document useful (0 votes)
9 views32 pages

Mad Programs

Uploaded by

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

Mad Programs

Uploaded by

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

1.

Develop a program to implement custom toast alert


XML.file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

</LinearLayout>

Java file :
package com.example.simpletoast;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.buttonToast);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Hello, this is a toast!", Toast.LENGTH_SHORT).show();
}
});
}
}
2.Develop 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="http://schemas.android.com/apk/res/android"
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 com.example.logdemo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

// Tag used for logging


private static final String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: Activity created"); // Log when activity is created

Button logButton = findViewById(R.id.logButton);


logButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "Button clicked!"); // Log on button click
}
});
}
}

3.Develop a program to implement new activity using explicit intent and implicit intent.
xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/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 com.example.exp3;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity
{
Button b1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=findViewById(R.id.btn1);
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent i=new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("Tel :"));
startActivity(i);
}
});
}
}

4.Develop a program AutocompleteTextview.


Xml file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

<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 com.example.pdf1;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity


{
private AutoCompleteTextView ac;
private String[] subjects={"Android","Python","PHP","ETI","EDE","Management"};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ac=findViewById(R.id.a1);
ArrayAdapter<String> adapter=new ArrayAdapter<>
(this, android.R.layout.simple_dropdown_item_1line,subjects);
ac.setAdapter(adapter);
}
}

5.Develop a program to implement sensors.

6.Develop a program to build a camera.

7.Develop program for Broadcasr receiver

8.Develop program for Radiogroup

Xml file :

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


<LinearLayout 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: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 com.example.pdf1;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity


{
RadioButton rb;
RadioGroup rg;
Button b;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=findViewById(R.id.button2);
rg=findViewById(R.id.radioGroup);

b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int selected=rg.getCheckedRadioButtonId();
if(selected!=1)
{
rb=findViewById(selected);
Toast.makeText(getApplicationContext(),rb.getText(),Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(),"Please select an
Option",Toast.LENGTH_LONG).show();
}
}
});
}
}

9.Develop a program for Bluetooth connectivity.

10.Develop a program for checkbox.

Xml file :

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


<RelativeLayout 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: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 com.example.exp10;
import android.os.Bundle;

import android.view.View;

import android.widget.CheckBox;

import android.widget.Toast;

import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

CheckBox c1, c2, c3, c4, c5;

Button b1;

String s;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

c1=(CheckBox) findViewById(R.id.checkBox1);

c2=(CheckBox) findViewById(R.id.checkBox2);

c3=(CheckBox) findViewById(R.id.checkBox3);

c4=(CheckBox) findViewById(R.id.checkBox4);

c5=(CheckBox) findViewById(R.id.checkBox5);

b1=(Button) findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

s=" ";

if(c1.isChecked())

s=s+c1.getText().toString()+"\n";

if(c2.isChecked())

s=s+c2.getText().toString()+"\n";

if(c3.isChecked())

s=s+c3.getText().toString()+"\n";

if(c4.isChecked())

s=s+c4.getText().toString()+"\n";

if(c5.isChecked())

s=s+c5.getText().toString()+"\n";
}

Toast.makeText(getApplicationContext(),"Selected Subjects : \
n"+s,Toast.LENGTH_LONG).show();

});

11.Develop a program for ListView.

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

<LinearLayout 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: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 com.example.exp11;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.AdapterView;

import android.widget.ListView;

import android.widget.TextView;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

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) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

l=(ListView) findViewById(R.id.listView);

ArrayAdapter adapter=new
ArrayAdapter<String>(this,androidx.appcompat.R.layout.support_simple_spinner_dropdown_item,city);

l.setAdapter(adapter);
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

Toast.makeText(MainActivity.this,((TextView)view).getText(),Toast.LENGTH_LONG).show();

});

12.Write a program to display circular progressbar

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

<LinearLayout 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: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 com.example.exp12;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.ProgressBar;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


ProgressBar p;

Button b;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

p=findViewById(R.id.progressBar);

b=findViewById(R.id.button);

b.setOnClickListener(View::invalidate);

p.setVisibility(View.VISIBLE);

13.Develop a program for Toggle Button.

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

<RelativeLayout 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">
<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 com.example.exp13;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.ToggleButton;

import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

ToggleButton t;

Button btn;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

t=(ToggleButton) findViewById(R.id.toggleButton);

btn=(Button) findViewById(R.id.button);

btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

if(t.isChecked())

Toast.makeText(getApplicationContext(),"Bluetooth is ON",Toast.LENGTH_LONG).show();

else

Toast.makeText(getApplicationContext(),"Bluetooth is OFF",Toast.LENGTH_LONG).show();

}
});

14.Develop a program for Gridview.

<?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">

<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"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Java file :

package com.example.exp14;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;

import androidx.appcompat.app.AppCompatActivity;

import android.widget.Toast;

import android.widget.GridView;

import android.widget.ArrayAdapter;

import android.widget.AdapterView;

import android.view.View;

public class MainActivity extends AppCompatActivity

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);

setContentView(R.layout.activity_main);

GridView gv=findViewById(R.id.g);

String[] labels=new String[15];

for(int i=0;i<15;i++)

labels[i] = "Button" + (i + 1);

ArrayAdapter<String>adapter=new ArrayAdapter<>(this,

android.R.layout.simple_list_item_1,labels);

gv.setAdapter(adapter);

gv.setOnItemClickListener(new AdapterView.OnItemClickListener()

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

String buttonlabel=((String)parent.getItemAtPosition(position));

Toast.makeText(MainActivity.this,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="http://schemas.android.com/apk/res/android"

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="http://schemas.android.com/apk/res/android"

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>

You might also like