?
UI interface:
?
Xml:
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:paddingleft= "@dimen/activity_horizontal_margin"
android:paddingright= "@dimen/activity_horizontal_margin"
android:paddingtop= "@dimen/activity_vertical_margin"
android:paddingbottom= "@dimen/activity_vertical_margin"
android:background= "@color/black"
Tools:context= ". MyActivity ">
?
<linearlayout
?
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical" >
?
<textview
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "@string/listtile"
Android:textcolor= "@color/white"
Android:textsize= "32DP"/>
<scrollview
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content" >
<linearlayout
Android:id= "@+id/root"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical"
>
?
</LinearLayout>
</ScrollView>
</LinearLayout>
?
</RelativeLayout>
?
Java:
LinearLayout sensoelayout;
Boolean b=boolean.true;
?
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (r.layout.activity_my);
?
sensoelayout= (LinearLayout) Findviewbyid (r.id.root);
?
Sensormanager sm = (Sensormanager) getsystemservice (Context.sensor_service);
?
list<sensor> allsensors = sm.getsensorlist (Sensor.type_all);
?
int i=1;
for (Sensor s:allsensors)
{
?
TextView tv=new TextView (this);
Tv.setid (i);
Tv.settext (i + "Name:" + s.getname () + "\ n Vendor:" + s.getvendor () +
"\ n Type:" + s.gettype () +
"\ n maximumrange:" + s.getmaximumrange ()
+ "\ n Version:" + s.getversion () +
"\ n Power:" + s.getpower ()
);
?
?
Tv.settextsize (23);
?
if (b)
{
Tv.settextcolor (Color.green);
}
Else
{
Tv.settextcolor (color.red);
}
B=!b;
Sensoelayout.addview (TV);
i++;
?
?
}
The code above uses two sensor libraries:
Import Android.hardware.Sensor;
Import Android.hardware.SensorManager;
?
?