Software Applications For Mobile Devices: Lab Journal 5
Software Applications For Mobile Devices: Lab Journal 5
Software Applications For Mobile Devices: Lab Journal 5
Devices
Lab Journal 5
BAHRIA UNIVERSITY
ISLAMABAD CAMPUS
Objective:
Tools Used:
Snipping Tool
Android Studio
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:orientation="vertical"
>
<EditText
android:id="@+id/name"
android:layout_width="339dp"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
></EditText>
<EditText
android:id="@+id/dOB"
android:layout_width="339dp"
android:layout_height="wrap_content"
android:inputType="date"
android:hint="Enter your Date of Birth"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
></EditText>
<AutoCompleteTextView
android:layout_width="339dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:hint="Enter city"
android:id="@+id/city"
></AutoCompleteTextView>
<AutoCompleteTextView
android:layout_width="339dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:hint="Enter Country"
android:id="@+id/country"
></AutoCompleteTextView>
<Spinner
android:id="@+id/spinner"
android:layout_width="339dp"
android:layout_height="40dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:hint="Education"
/>
<Button
android:id="@+id/button"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Process"></Button>
</LinearLayout>
</RelativeLayout>
MainActivity.java
package com.example.lab5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.Spinner;
EditText editText;
Spinner spinner;
AutoCompleteTextView autoCompleteTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EDU = getResources().getStringArray(R.array.Education);
}
}
strings.xml
<resources>
<string name="app_name">Lab5</string>
<string-array name="Education">
<item>BS</item>
<item>BBA</item>
<item>BE</item>
<item>PhD</item>
<item>MPhil</item>
</string-array>
</resources>
Task 2
MainActivity.java
package com.example.lab5;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
Intent i;
EditText name_user;
EditText date_user;
Spinner sp_user;
Button button_user;
AutoCompleteTextView cT_user;
AutoCompleteTextView cont_user;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EDU = getResources().getStringArray(R.array.Education);
i = new Intent(MainActivity.this,MainActivity2.class);
i.putExtra("na" , name_user.getText().toString());
i.putExtra("dob" , date_user.getText().toString());
i.putExtra("city" , cT_user.getText().toString());
i.putExtra("country" , cont_user.getText().toString());
i.putExtra("edu" , sp_user.getSelectedItem().toString());
startActivity(i);
}
});
}
}
Activity_main.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:orientation="vertical"
>
<EditText
android:id="@+id/name"
android:layout_width="339dp"
android:layout_height="wrap_content"
android:hint="Enter your name"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:inputType="textPersonName"
/>
<EditText
android:id="@+id/dOB"
android:layout_width="339dp"
android:layout_height="wrap_content"
android:inputType="date"
android:hint="Enter your Date of Birth"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
/>
<AutoCompleteTextView
android:layout_width="339dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:hint="Enter city"
android:id="@+id/city"
android:inputType="textPersonName"
/>
<AutoCompleteTextView
android:layout_width="339dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:hint="Enter Country"
android:id="@+id/country"
android:inputType="textPersonName"
/>
<Spinner
android:id="@+id/spinner"
android:layout_width="339dp"
android:layout_height="40dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"
android:hint="Education"
/>
<Button
android:id="@+id/button"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Process"/>
</LinearLayout>
</RelativeLayout>
Activity_main2.xml
<TextView
android:textSize="20dp"
android:id="@+id/na"
android:layout_width="323dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="30dp"/>
<TextView
android:id="@+id/dateof"
android:layout_width="323dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:textSize="20dp"
android:layout_marginTop="30dp"/>
<TextView
android:id="@+id/co"
android:layout_width="323dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:textSize="20dp"
android:layout_marginTop="30dp"/>
<TextView
android:id="@+id/cou"
android:layout_width="323dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:textSize="20dp"
android:layout_marginTop="30dp"/>
<TextView
android:id="@+id/educ"
android:layout_width="323dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:textSize="20dp"
android:layout_marginTop="30dp"/>
</LinearLayout>
MainActivity2.java
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
TextView textView;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Intent i2 = getIntent();
String a,b,c,d,e;
a= "Name: " + i2.getExtras().getString("na");
b= "Date of Birth: " + i2.getExtras().getString("dob");
c= "City: " + i2.getExtras().getString("city");
d= "Country: " + i2.getExtras().getString("country");
e= "Education: " + i2.getExtras().getString("edu");
t1.setText(a);
t2.setText(b);
t3.setText(c);
t4.setText(d);
t5.setText(e);
}
}
Task 3
Conclusion:
In this lab we learned about array adapters and spinners. The given tasks were completed successfully.