Mobile Lab
Mobile Lab
Mobile Lab
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/tvCreateAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/create_an_account"
android:textSize="24sp"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:paddingBottom="20dp" />
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
android:inputType="textPersonName"
android:padding="10dp" />
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:padding="10dp"
android:layout_marginTop="10dp" />
<EditText
android:id="@+id/etMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/mobile_number"
android:inputType="phone"
android:padding="10dp"
android:layout_marginTop="10dp" />
<Spinner
android:id="@+id/spinnerEmploymentType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
<CheckBox
android:id="@+id/cbWorkHourly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/work_hourly"
android:layout_marginTop="20dp" />
<CheckBox
android:id="@+id/cbWorkMonthly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/works_monthly"
android:layout_marginTop="5dp" />
<TextView
android:id="@+id/tvOvertime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/available_for_overtime"
android:layout_marginTop="20dp" />
<RadioGroup
android:id="@+id/rgOvertime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<RadioButton
android:id="@+id/rbYes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yes" />
<RadioButton
android:id="@+id/rbNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no"
android:layout_marginStart="20dp" />
</RadioGroup>
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/submit"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:padding="10dp" />
</LinearLayout>
MainActivity.java
package www.biplapneupane.com.np.practical_lab;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
activityMain2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/main"
android:padding="16dp">
<TextView
android:id="@+id/tvCreateAccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/intent_example"
android:textSize="24sp"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:paddingBottom="20dp" />
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
android:inputType="textPersonName" />
MainActivity.java
package www.biplapneupane.com.np.practical_lab;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main2);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
etName = findViewById(R.id.etName);
etAddress = findViewById(R.id.etAddress);
etEmail = findViewById(R.id.etEmail);
etMobile = findViewById(R.id.etMobile);
btnSubmit = findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity2.this, Activity2_display.class);
intent.putExtra("NAME", etName.getText().toString());
intent.putExtra("ADDRESS", etAddress.getText().toString());
intent.putExtra("EMAIL", etEmail.getText().toString());
intent.putExtra("MOBILE", etMobile.getText().toString());
startActivity(intent);
}
});
}
}
Activity2Display.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:background="@android:color/white">
</LinearLayout>
activity2_display.java
package www.biplapneupane.com.np.practical_lab;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_activity2_display);
ViewCompat.setOnApplyWindowInsetsListener
(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets
(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top,
systemBars.right, systemBars.bottom);
return insets;
});
Activity_color_choose.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:id="@+id/main"
android:padding="16dp">
<Button
android:id="@+id/btn_choose_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose Color" />
<Button
android:id="@+id/btn_popup_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Popup Menu" />
<Button
android:id="@+id/btn_alert_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Alert Dialog"/>
</LinearLayout>
chooseColor.java
package www.biplapneupane.com.np.practical_lab;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
});
popupMenu.show();
}
});
btn_alert_dialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(ColorChoose.this);
AlertDialog alertDialog = builder.create();
builder.setTitle("Are you sure ?");
builder.setMessage("Do you want to continue enter ok other wise click cancel");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Toast.makeText(ColorChoose.this,"OK
Selected",Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Toast.makeText(ColorChoose.this,"Cancel
Selected",Toast.LENGTH_SHORT).show();
}
});
builder.show();
}
});
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Choose Menu");
// Dynamically adding menu items
menu.add("Black");
menu.add("Red");
menu.add("Yellow");
menu.add("White");
menu.add("Green");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
String title = item.getTitle().toString();
if (title.equals("Black")) {
Toast.makeText(this, "Black selected", Toast.LENGTH_SHORT).show();
} else if (title.equals("Red")) {
Toast.makeText(this, "Red selected", Toast.LENGTH_SHORT).show();
} else if (title.equals("Yellow")) {
Toast.makeText(this, "Yellow selected", Toast.LENGTH_SHORT).show();
} else if (title.equals("White")) {
Toast.makeText(this, "White selected", Toast.LENGTH_SHORT).show();
} else if (title.equals("Green")) {
Toast.makeText(this, "Green selected", Toast.LENGTH_SHORT).show();
} else {
return super.onContextItemSelected(item);
}
return true;
}
options_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/edit"
android:title="edit"
app:showAsAction="always"/>
<item
android:id="@+id/save"
android:title="save"
app:showAsAction="always"/>
<item
android:id="@+id/update"
android:title="update"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/delete"
android:title="delete"
app:showAsAction="ifRoom"/>
</menu>
popup_menu.xml
ListView_Activity.java
package www.biplapneupane.com.np.practical_lab;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
int[] itemImages = {
R.drawable.pizza, R.drawable.burger, R.drawable.pasta,
R.drawable.sushi, R.drawable.tacos, R.drawable.sandwich,
R.drawable.salad, R.drawable.ice_cream, R.drawable.chocolate,
R.drawable.fried_chicken
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_list_view);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main),
(v, insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});
listView = findViewById(R.id.listView);
CustomListAdapter customListAdapter = new
CustomListAdapter(ListView_Activity.this, foodItems, itemImages);
listView.setAdapter(customListAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Toast.makeText(ListView_Activity.this, "Selected: " +
foodItems[position], Toast.LENGTH_SHORT).show();
}
});
}
}
CustomListAdapter.java
package www.biplapneupane.com.np.practical_lab;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
ActivityListView.xml
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"
android:divider="@color/black"
android:dividerHeight="5dp"
/>
</RelativeLayout>
listView.xml
<TextView
android:id="@+id/listTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:textColor="@color/black"
android:textStyle="bold" />
</LinearLayout>
Grid View
GridView.java
package www.biplapneupane.com.np.practical_lab;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
android.widget.GridView gridView;
String[] countries = {
"USA", "Nepal", "Bhutan", "Shri Lanka.", "Pakistan", "Italy",
"Japan", "China", "India", "Brazil", "Australia"
};
int[] countryFlags = {
R.drawable.usa, R.drawable.nepal, R.drawable.bhutan,
R.drawable.shrilanka, R.drawable.pakistan, R.drawable.italy,
R.drawable.japan, R.drawable.china, R.drawable.india,
R.drawable.brasil, R.drawable.aus
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_grid_view);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
gridView= findViewById(R.id.gridView);
CustomGridAdapter customGridAdapter = new
CustomGridAdapter(GridView.this,countries,countryFlags);
gridView.setAdapter(customGridAdapter);
}
}
CustomGridAdapetr.java
package www.biplapneupane.com.np.practical_lab;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
int[] imageItems;
Context mContext;
String[] countries;
int[] laanguageItems;
LayoutInflater layoutInflater;
return convertView;
}
}
activity_grid_view.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GridView"
android:layout_marginTop="@dimen/cardview_compat_inset_shadow" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="25sp"
android:layout_marginTop="15dp"
android:id="@+id/textView"/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:id="@+id/gridView"
android:layout_below="@id/textView"
android:layout_marginTop="20dp"/>
</RelativeLayout>
layout_grid.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:id="@+id/imageItemGrid"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textItemGrid"
android:layout_centerHorizontal="true"
android:layout_below="@+id/imageItemGrid"
android:layout_marginBottom="20dp"
android:text="@string/app_name"
/>
</RelativeLayout>
RecyclerView
RecyclerView.java
package www.biplapneupane.com.np.practical_lab;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
androidx.recyclerview.widget.RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_recycler_view);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
recyclerView=findViewById(R.id.recyclerView);
RecyclerDTO[] recyclerDTOS=new RecyclerDTO[]{
new RecyclerDTO("Nepal", "Nepal is a landlocked country in Asia, known for its
stunning Himalayan landscapes and cultural heritage.", "Asia", "Kathmandu",
R.drawable.nepal),
new RecyclerDTO("Bhutan", "Bhutan is a landlocked country in Asia, known for its
mountainous terrain and rich culture.", "Asia", "Thimphu", R.drawable.bhutan),
new RecyclerDTO("Pakistan", "Pakistan is a country in South Asia known for its
diverse landscapes and rich history.", "Asia", "Islamabad", R.drawable.pakistan),
new RecyclerDTO("India", "India is a country in South Asia known for its diverse
culture, languages, and landscapes.", "Asia", "New Delhi", R.drawable.india),
new RecyclerDTO("Sri Lanka", "Sri Lanka is an island country in South Asia known
for its tropical beaches and cultural heritage.", "Asia", "Colombo", R.drawable.shrilanka),
new RecyclerDTO("USA", "The United States is a country in North America known
for its diverse culture and landscapes.", "North America", "Washington, D.C.", R.drawable.usa),
};
RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(recyclerDTOS);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(recyclerViewAdapter);
}
}
RecyclerDTO.java
package www.biplapneupane.com.np.practical_lab;
public class RecyclerDTO {
String country;
String discription;
String continent;
String capital;
int images;
public RecyclerDTO(String country, String discription, String continent, String capital, int
images) {
this.country = country;
this.discription = discription;
this.continent = continent;
this.capital = capital;
this.images = images;
}
RecyclerViewAdapter.java
package www.biplapneupane.com.np.practical_lab;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.recycler_view_items, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
RecyclerDTO recyclerDTO = recyclerDTOS[position];
holder.countryTextView.setText(recyclerDTO.getcountry());
holder.capitalTextView.setText(recyclerDTO.getCapital());
holder.continentTextView.setText(recyclerDTO.getContinent());
holder.descriptionTextView.setText(recyclerDTO.getDiscription());
holder.imageView.setImageResource(recyclerDTO.getImages());
}
@Override
public int getItemCount() {
return recyclerDTOS.length;
}
Recycler_view_items.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<LinearLayout
android:id="@+id/leftColumn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentStart="true"
android:layout_marginEnd="16dp">
<ImageView
android:id="@+id/recyclerImageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/editing"
android:layout_marginBottom="8dp" />
<TextView
android:id="@+id/recyclerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="18sp"
android:textColor="#000000"
android:gravity="center"
android:layout_marginBottom="4dp" />
<TextView
android:id="@+id/capitalOfCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capital"
android:textSize="14sp"
android:textColor="#757575"
android:gravity="center"
android:layout_marginBottom="4dp" />
<TextView
android:id="@+id/continentOfCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Continent"
android:textSize="14sp"
android:textColor="#757575"
android:gravity="center" />
</LinearLayout>
<TextView
android:id="@+id/descriptionOfCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/leftColumn"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="Description"
android:textSize="16sp"
android:textColor="#000000"
android:gravity="center"
android:padding="16dp"
android:background="#FFFFFF"
android:elevation="2dp" />
android:background="@color/cardview_dark_background" />
</RelativeLayout>
Activity_recycler_view.xml
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practical_Lab"
tools:targetApi="31">
<activity
android:name=".GridView"
android:exported="false" />
<activity
android:name=".ListView_Activity"
android:exported="false" />
<activity
android:name=".ColorChoose"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="false" />
<activity
android:name=".Activity2_display"
android:exported="false" />
<activity
android:name=".MainActivity2"
android:exported="false" />
<activity
android:name=".RecyclerView"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>