0% found this document useful (0 votes)
13 views4 pages

MAD Practical No.22 Sensors

The document contains two practical programming tasks completed by Deepak Yadav, focusing on Android development. The first task involves writing a program to display a list of sensors supported by a mobile device, while the second task demonstrates the use of fragments in an Android application. Each task includes XML layout code and Java code necessary for implementation.
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)
13 views4 pages

MAD Practical No.22 Sensors

The document contains two practical programming tasks completed by Deepak Yadav, focusing on Android development. The first task involves writing a program to display a list of sensors supported by a mobile device, while the second task demonstrates the use of fragments in an Android application. Each task includes XML layout code and Java code necessary for implementation.
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/ 4

Name: Deepak Yadav

Roll No: 220463

Practical No. 22: Develop program to implement sensors


1. Write a Program to display the list of sensors supported by the mobile device.
CODE:
XML:
<?xml version="1.0" tools:context=".MainActivity">
encoding="utf-8"?> <TextView
<LinearLayout android:id="@+id/sensorslist"
xmlns:android="http://schemas.and android:layout_width="wrap_conte
roid.com/apk/res/android" nt"
android:layout_height="wrap_cont
xmlns:app="http://schemas.android ent"
.com/apk/res-auto" android:layout_marginTop="20dp"
android:text="Sensors"
xmlns:tools="http://schemas.androi android:textSize="16dp"
d.com/tools" android:textStyle="bold"
android:layout_width="match_pare android:layout_gravity="center"
nt" android:visibility="gone"/>
android:layout_height="match_par </LinearLayout>
ent"

JAVA:
package com.example.exp22;
setContentView(R.layout.activity_
import main);
androidx.appcompat.app.AppComp mgr =
atActivity; (SensorManager)getSystemService
import android.content.Context; (Context.SENSOR_SERVICE);
import android.hardware.Sensor; txtList =
import (TextView)findViewById(R.id.sens
android.hardware.SensorManager; orslist);
import android.os.Bundle; List<Sensor> sensorList =
import android.view.View; mgr.getSensorList(Sensor.TYPE_A
import android.widget.TextView; LL);
import java.util.List; StringBuilder strBuilder =
new StringBuilder();
public class MainActivity extends for(Sensor s: sensorList){
AppCompatActivity { strBuilder.append(s.getName()+"\
private SensorManager mgr; n");
private TextView txtList; }
@Override txtList.setVisibility(View.VISIBLE
protected void onCreate(Bundle );
savedInstanceState) { txtList.setText(strBuilder);
super.onCreate(savedInstanceState) }
; }

OUTPUT:
Name: Deepak Yadav
Roll No: 220463

2. Write a Program to demonstrate Fragments.


CODE:
XML:
activity_main2.xml:
<?xml version="1.0" android:layout_height="match_par
encoding="utf-8"?> ent"
<LinearLayout android:layout_width="350px"
xmlns:android="http://schemas.and class="com.example.exp22.Listite
roid.com/apk/res/android" ms_info"
xmlns:tools="http://schemas.androi android:id="@+id/fragment"/>
d.com/tools" <fragment
android:layout_width="match_pare android:layout_width="match_pare
nt" nt"
android:layout_height="match_par android:layout_height="match_par
ent" ent"
android:orientation="horizontal" class="com.example.exp22.Detailsi
tools:context="com.example.exp22 nfo"
.MainActivity2"> android:id="@+id/fragment2"/>
<fragment </LinearLayout>

details_info.xml:
<?xml version="1.0"
encoding="utf-8"?> android:background="#0079D6">
<LinearLayout <TextView
xmlns:android="http://schemas.and android:layout_width="wrap_conte
roid.com/apk/res/android" nt"
android:orientation="vertical" android:layout_height="wrap_cont
android:layout_width="match_pare ent"
nt" android:textColor="#ffffff"
android:layout_height="match_par android:layout_marginTop="200px
ent" "
Name: Deepak Yadav
Roll No: 220463

android:layout_marginLeft="200px android:layout_height="wrap_cont
" ent"
android:id="@+id/Name"/> android:layout_marginLeft="200px
<TextView "
android:layout_width="wrap_conte android:textColor="#ffffff"
nt" android:id="@+id/Location"/>
</LinearLayout>

listitems_info.xml:
<?xml version="1.0" android:layout_height="match_par
encoding="utf-8"?> ent">
<LinearLayout <ListView
xmlns:android="http://schemas.and android:layout_width="match_pare
roid.com/apk/res/android" nt"
android:orientation="vertical" android:layout_height="wrap_cont
android:layout_width="match_pare ent"
nt"
android:id="@android:id/list" />
</LinearLayout>

JAVA:
Mainactivity2.java:
package com.example.exp22; protected void onCreate(Bundle
import android.os.Bundle; savedInstanceState) {
import super.onCreate(savedInstanceState);
androidx.appcompat.app.AppComp setContentView(R.layout.activity_
atActivity; main2);
}
public class MainActivity2 extends }
AppCompatActivity {

Detailsinfo.java:
package com.example.exp22; View view =
import android.os.Bundle; inflater.inflate(R.layout.details_inf
import o, container, false);
androidx.fragment.app.Fragment; name =
import (TextView)view.findViewById(R.i
android.view.LayoutInflater; d.Name);
import android.view.View; location =
import android.view.ViewGroup; (TextView)view.findViewById(R.i
import android.widget.TextView; d.Location);
return view;
public class Detailsinfo extends }
Fragment { public void change(String
TextView name,location; uname, String ulocation){
@Override name.setText(uname);
public View location.setText(ulocation);
onCreateView(LayoutInflater }
inflater, ViewGroup container, }
Bundle savedInstanceState) {
Name: Deepak Yadav
Roll No: 220463

Listitems_info.java:
package com.example.exp22; View view
=inflater.inflate(R.layout.listitems_
import android.os.Bundle; info, container, false);
import ArrayAdapter<String> adapter
androidx.fragment.app.Fragment; = new
import ArrayAdapter<String>(getActivity(
androidx.fragment.app.ListFragme ),
nt; android.R.layout.simple_list_item_
import 1, users);
android.view.LayoutInflater; setListAdapter(adapter);
import android.view.View; return view; }
import android.view.ViewGroup; @Override
import public void
android.widget.ArrayAdapter; onListItemClick(ListView l, View
import android.widget.ListView; v, int position, long id) {
Detailsinfo txt = (Detailsinfo)
public class Listitems_info extends getFragmentManager().findFragme
ListFragment { ntById(R.id.fragment2);
String[] users = new String[] txt.change("Name: "+
{ "Midhat","Sidrah","Aysha" }; users[position],"Location : "+
String[] location = new String[] location[position]);
{"Byculla","Wadala","Agripada",}; getListView().setSelector(android.
@Override R.color.holo_blue_dark);
public View }
onCreateView(LayoutInflater }
inflater, ViewGroup container,
Bundle savedInstanceState) {

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy