Android Pgms
Android Pgms
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="create_db"
android:text="Create database"/>
</LinearLayout>
package com.example.msbte_exam_practice;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
2] image button
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/teal_700"
android:src="@drawable/img"/>
3) absolute layout
To send sms :
<?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:layout_width="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/edtPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:textSize="20sp"></EditText>
<EditText
android:id="@+id/edtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Message"
android:textSize="20sp"></EditText>
<Button
android:id="@+id/btnsendSMS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Send SMS"></Button>
</LinearLayout>
MANIFEST :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permisssion.SEND_SMS"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MSBTE_EXAM_Practice"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Java:
package com.example.msbte_exam_practice;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.Manifest;
public class MainActivity extends AppCompatActivity {
Button snd;
EditText phno,msg;
SmsManager smsManager;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtPhoneNumber = findViewById(R.id.edtPhoneNumber);
edtMessage = findViewById(R.id.edtMessage);
btnSendSMS = findViewById(R.id.btnsendSMS);
btnSendSMS.setOnClickListener(view->{
String phoneNumber = edtPhoneNumber.getText().toString();
String message = edtMessage.getText().toString();
}
7) Celsius to farahnite and vice a varsa
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/temp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter temperature"/>
<ToggleButton
android:id="@+id/tbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="F to C"
android:layout_gravity="center"
android:textOn="C to F"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="click"
android:id="@+id/btn"/>
</LinearLayout>
Java:
package com.example.msbte_exam_practice;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;
Button b1;
Double a;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tb=findViewById(R.id.tbtn);
e1=findViewById(R.id.temp);
b1=findViewById(R.id.btn);
b1.setOnClickListener(view -> {
if(tb.isChecked()){
a=Double.parseDouble(String.valueOf(e1.getText()));
Double b=a*9/5+32;
String r=String.valueOf(b);
Toast.makeText(this,r+ "F", Toast.LENGTH_SHORT).show();
}
else{
a=Double.parseDouble(String.valueOf(e1.getText()));
Double b=a-32;
Double c=b*5/9;
String r=String.valueOf(c);
Toast.makeText(this, r+"C", Toast.LENGTH_SHORT).show();
}
});
8) camera pr program
tools:context=".MainActivity">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b0"
android:layout_marginHorizontal="20dp"
android:text="0"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:layout_marginHorizontal="30dp"
android:text="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b2"
android:layout_marginHorizontal="20dp"
android:text="2"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b3"
android:layout_marginHorizontal="20dp"
android:text="3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b4"
android:layout_marginHorizontal="20dp"
android:text="4"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b5"
android:layout_marginHorizontal="20dp"
android:text="5"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b6"
android:layout_marginHorizontal="20dp"
android:text="6"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b7"
android:layout_marginHorizontal="20dp"
android:text="7"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b8"
android:layout_marginHorizontal="20dp"
android:text="8"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b9"
android:layout_marginHorizontal="20dp"
android:text="9"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/submit"
android:layout_marginHorizontal="20dp"
android:text="submit"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clear"
android:layout_marginHorizontal="20dp"
android:text="clear"/>
</TableRow>
</TableLayout>
Java :
package com.example.msbte_exam_practice;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
clear=findViewById(R.id.clear);
submit=findViewById(R.id.submit);
b0.setOnClickListener(view -> {
txt.append(b0.getText().toString()+" ");
});
b1.setOnClickListener(view -> {
txt.append(b1.getText().toString()+" ");
});
b2.setOnClickListener(view -> {
txt.append(b2.getText().toString()+" ");
});
b3.setOnClickListener(view -> {
txt.append(b3.getText().toString()+" ");
});
b4.setOnClickListener(view -> {
txt.append(b4.getText().toString()+" ");
});
b5.setOnClickListener(view -> {
txt.append(b5.getText().toString()+" ");
});
b6.setOnClickListener(view -> {
txt.append(b6.getText().toString()+" ");
});
b7.setOnClickListener(view -> {
txt.append(b7.getText().toString()+" ");
});
b8.setOnClickListener(view -> {
txt.append(b8.getText().toString()+" ");
});
b9.setOnClickListener(view -> {
txt.append(b9.getText().toString()+" ");
});
submit.setOnClickListener(view -> {
Toast.makeText(this, "You have clicked :"+txt, Toast.LENGTH_SHORT).show();
});
clear.setOnClickListener(view->{
txt.setLength(0);
});
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/pb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:indeterminate="false"
android:max="100"
android:minHeight="50dp"
android:maxWidth="200dp"
android:progress="1"/>
<TextView
android:id="@+id/txt"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="progressstatus"/>
</LinearLayout>
Java :
package com.example.msbte_exam_practice;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
pb=findViewById(R.id.pb);
txt=findViewById(R.id.txt);
}
14) geocoding and reverse geocoding
17) list view of 5 items, grid view of 4*4 items, image view
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="30dp"
tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/list"/>
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/grid"
android:columnWidth="50dp"
android:layout_gravity="center"
android:numColumns="4"
android:stretchMode="columnWidth"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/image"
android:src="@drawable/img"/>
</LinearLayout>
Java :
package com.example.msbte_exam_practice;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
// gridview
GridView grid=findViewById(R.id.grid);
adp2=new ArrayAdapter(this, android.R.layout.simple_list_item_1,alphabets);
grid.setAdapter(adp2);
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Insert Customer Details"
android:textSize="20sp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etid"
android:hint="ID"
android:layout_marginTop="20dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etname"
android:hint="Name"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etmbno"
android:hint="Mobile Number"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etaddress"
android:hint="Address"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etpin"
android:hint="PinCode"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Insert Data"
android:layout_marginTop="30dp"
android:id="@+id/btnInsert"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etsearchid"
android:layout_marginTop="30dp"
android:hint="Enter id To search"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search Data"
android:layout_marginTop="30dp"
android:id="@+id/btnSearch"/>
</LinearLayout>
Java:
package com.example.msbte_exam_practice;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
etid=findViewById(R.id.etid);
etname=findViewById(R.id.etname);
etmbno=findViewById(R.id.etmbno);
etaddress=findViewById(R.id.etaddress);
etpin=findViewById(R.id.etpin);
etsearchid=findViewById(R.id.etsearchid);
btninsert=findViewById(R.id.btnInsert);
btnsearch=findViewById(R.id.btnSearch);
btninsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sqLiteDatabase=openOrCreateDatabase("USERS", Context.MODE_PRIVATE,null);
sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS usersdata(id INTEGER
PRIMARY KEY AUTOINCREMENT NOT NULL,cid VARCHAR,name VARCHAR,mobile VARCHAR,address
VARCHAR, pincode VARCHAR );");
cid=etid.getText().toString();
cname=etname.getText().toString();
cmbno=etmbno.getText().toString();
caddress=etaddress.getText().toString();
cpin=etpin.getText().toString();
btnsearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sid=etsearchid.getText().toString();
Cursor cursor=sqLiteDatabase.rawQuery("select * from usersdata where
cid="+sid+"",null);
StringBuffer str=new StringBuffer();
while(cursor.moveToNext()){
String cid=cursor.getString(1);
String name=cursor.getString(2);
String mob=cursor.getString(3);
String addr=cursor.getString(4);
String pcode=cursor.getString(5);
str.append(cid+" "+name+" "+mob+" "+addr+" "+pcode+" ");
Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
}
}
});
}
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculator"
android:textSize="20sp"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="Enter number 1"
android:id="@+id/no1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/no1"
android:id="@+id/no2"
android:hint="Enter number 2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/no2"
android:layout_marginTop="30dp"
android:text="+"
android:id="@+id/add"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/add"
android:layout_below="@+id/no2"
android:layout_marginTop="30dp"
android:text="-"
android:layout_marginLeft="20dp"
android:id="@+id/sub"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/add"
android:text="*"
android:id="@+id/mul"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/div"
android:layout_below="@id/sub"
android:layout_toRightOf="@+id/mul"
android:layout_marginLeft="20dp"
android:text="/"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/mul"
android:layout_marginTop="40dp"
android:id="@+id/res"/>
</RelativeLayout>
Java:
package com.example.calculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
t1=findViewById(R.id.no1);
t2=findViewById(R.id.no2);
b1=findViewById(R.id.add);
b2=findViewById(R.id.sub);
b3=findViewById(R.id.mul);
b4=findViewById(R.id.div);
res=findViewById(R.id.res);
b1.setOnClickListener(view -> {
int
sum=Integer.parseInt(t1.getText().toString())+Integer.parseInt(t2.getText().toString());
res.setText("Addition is : "+sum);
});
b2.setOnClickListener(view->{
int sub=Integer.parseInt(t1.getText().toString())-
Integer.parseInt(t2.getText().toString());
res.setText("Subtraction is : "+sub);
});
b3.setOnClickListener(view -> {
int
mul=Integer.parseInt(t1.getText().toString())*Integer.parseInt(t2.getText().toString());
res.setText("Multiplication is : "+mul);
});
b4.setOnClickListener(view -> {
int
div=Integer.parseInt(t1.getText().toString())/Integer.parseInt(t2.getText().toString());
res.setText("Division is : "+div);
});
}
}