0% found this document useful (0 votes)
5 views16 pages

Android App Layouts and Activities

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)
5 views16 pages

Android App Layouts and Activities

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

CALCULATOR :

XML FILE :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:layout_width="411dp"
android:layout_height="50dp"
android:id="@+id/editText"
android:layout_marginTop="150dp"
android:ems="10"
android:hint="Enter the Number"
android:inputType="textPersonName"
android:text=""
android:textColor="#A125B6"/>

<EditText
android:layout_width="411dp"
android:layout_height="50dp"
android:id="@+id/editText2"
android:layout_marginTop="30dp"
android:layout_below="@+id/editText"
android:ems="10"
android:hint="Enter the Number"
android:inputType="textPersonName"
android:text=""
android:textColor="#A125B6"/>

<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/textview"
android:gravity="center"
android:text="calculator"
android:textSize="30dp"
android:textAllCaps="true"
android:textColor="#A125B6"
android:textStyle="bold"/>

<Button
android:layout_width="132dp"
android:layout_height="62dp"
android:id="@+id/button1"
android:layout_below="@+id/editText2"
android:layout_marginTop="36dp"
android:text="+"
android:gravity="center"
android:layout_marginLeft="10dp"/>

<Button
android:layout_width="132dp"
android:layout_height="62dp"
android:id="@+id/button2"
android:layout_below="@+id/editText2"
android:layout_marginTop="36dp"
android:text="-"
android:gravity="center"
android:layout_marginLeft="260dp"/>

<Button
android:layout_width="132dp"
android:layout_height="62dp"
android:id="@+id/button3"
android:layout_below="@+id/button1"
android:layout_marginTop="36dp"
android:text="*"
android:gravity="center"
android:layout_marginLeft="10dp"/>

<Button
android:layout_width="132dp"
android:layout_height="62dp"
android:id="@+id/button4"
android:layout_below="@+id/button2"
android:layout_marginTop="36dp"
android:text="%"
android:gravity="center"
android:layout_marginLeft="260dp"/>

</RelativeLayout>
MAIN ACTIVITY :
package [Link];
public class MainActivity extends AppCompatActivity {
EditText et1, et2;
TextView tv2;
Button add, sub, mul, div;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
et1 = findViewById([Link]);
et2 = findViewById([Link].editText2);
tv2 = findViewById([Link]);
add = findViewById([Link].button1);
sub = findViewById([Link].button2);
mul = findViewById([Link].button3);
div = findViewById([Link].button4);
[Link](new [Link]() {
@Override
public void onClick(View view) {
double a1= [Link]([Link]().toString());
doublea2 = [Link]([Link]().toString());
double result = a1 + a2;
[Link]([Link](result));
}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
doublea1 = [Link]([Link]().toString());
doublea2 = [Link]([Link]().toString());
double result = a1 - a2;
[Link]([Link](result));
}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
doublea1 = [Link]([Link]().toString());
doublea2 = [Link]([Link]().toString());
double result = a1 * a2;
[Link]([Link](result));
}
});
[Link](new [Link]() {
@Override
public void onClick(View view) {
doublea1 = [Link]([Link]().toString());
doublea2 = [Link]([Link]().toString());
double result = a1 / a2;
[Link]([Link](result));
}
});
}
}
MUSIC APP :

XML FILE :

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


<RelativeLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#F4BA98"
tools:context=".MainActivity">

<Button
android:id="@+id/playButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play Music"
android:textSize="30dp"
android:backgroundTint="#F6620E"
android:layout_centerInParent="true"/>

<ImageView
android:id="@+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img2" />

</RelativeLayout>
MAIN ACTIVITY:

package [Link];
public class MainActivity extends AppCompatActivity {

private MediaPlayer mediaPlayer;


private Button playButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

mediaPlayer = [Link](this, [Link]); // Replace with your


actual music file
playButton = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
if ([Link]()) {
[Link]();
[Link]("Play Music");
} else {
[Link]();
[Link]("Pause Music");
}
}
});
}

@Override
protected void onDestroy() {
[Link]();
if (mediaPlayer != null) {
[Link]();
}
}
}

This Activity we need create raw folder and then we need to add mp3
files....
CALENDER :
XML FILE :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>

MAIN ACTIVITY :
package [Link];

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

CalendarView calendarView;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

calendarView = findViewById([Link]);

// Set listener to handle date selection


[Link](new
[Link]() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view,
int year, int month, int dayOfMonth) {
// Handle selected date
String selectedDate = dayOfMonth + "/" + (month + 1) + "/" +
year;
[Link]([Link], "Selected Date: " +
selectedDate, Toast.LENGTH_SHORT).show();
}
});
}
}
CHECK BOX :
XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup">

<RadioButton
android:id="@+id/radioMale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Male"
android:layout_marginTop="10dp"
android:checked="false"
android:textSize="20dp" />

<RadioButton
android:id="@+id/radioFemale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Female"
android:layout_marginTop="20dp"
android:checked="false"

android:textSize="20dp" />
</RadioGroup>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:id="@+id/button"
android:onClick="onclickbuttonMethod"
android:layout_gravity="center_horizontal" />

</LinearLayout>

MAIN ACTIVITY :
package [Link];

import [Link];

public class MainActivity extends AppCompatActivity {


Button button;
RadioButton genderradioButton;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
radioGroup=(RadioGroup)findViewById([Link]);
}
public void onclickbuttonMethod(View v){
int selectedId = [Link]();
genderradioButton = (RadioButton) findViewById(selectedId);
if(selectedId==-1){
[Link]([Link],"Nothing selected",
Toast.LENGTH_SHORT).show();
}
else{
[Link]([Link],[Link](),
Toast.LENGTH_SHORT).show();
}

}
}
SMS MESSAGE :
XML :

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


<RelativeLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="80dp"
android:layout_marginRight="50dp"
android:ems="10"
android:hint="Type your number"
android:minHeight="48dp" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="26dp"
android:ems="10"
android:hint="Type your message"
android:inputType="textMultiLine"
android:minHeight="48dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_marginLeft="30dp"
android:textStyle="bold"
android:text="Mobile No:" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_alignBaseline="@+id/editText2"
android:layout_marginLeft="30dp"
android:text="Message:" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:textSize="30dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="48dp"
android:backgroundTint="#236810"
android:text="Send SMS" />

</RelativeLayout>

MAIN ACTIVITY :

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends Activity {

EditText mobileno,message;
Button sendsms;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

mobileno=(EditText)findViewById([Link].editText1);
message=(EditText)findViewById([Link].editText2);
sendsms=(Button)findViewById([Link].button1);

//Performing action on button click


[Link](new [Link]() {

@Override
public void onClick(View arg0) {
String no=[Link]().toString();
String msg=[Link]().toString();

//Getting intent and PendingIntent instance


Intent intent=new
Intent(getApplicationContext(),[Link]);
PendingIntent
pi=[Link](getApplicationContext(), 0, intent,
PendingIntent.FLAG_MUTABLE);
//Get the SmsManager instance and call the
sendTextMessage method to send message
SmsManager sms=[Link]();
[Link](no, null, msg, pi,null);

[Link](getApplicationContext(), "Message
Sent successfully!",
Toast.LENGTH_LONG).show();
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate([Link].activity_main, menu);
return true;
}

MAINFEST ACTIVITY :

<uses-feature
android:name="[Link]"
android:required="false" />
<uses-permission
android:name="[Link].SEND_SMS"/>

You might also like