Step-by-Step Guide: Creating a Simple Invoice
App in Android Studio
Target Audience: Beginner students learning Android App Development App Name:
Simple Invoice App
1. Introduction
In this handout, you will learn how to create a simple invoice app using Android Studio. The
app allows users to enter an item name, price, and quantity, and then adds the item to a
list while calculating the overall total.
2. Tools Needed
• Android Studio (latest version recommended)
• Java Development Kit (JDK)
• Basic knowledge of XML and Java
3. Project Setup
1. Open Android Studio.
2. Click on “New Project”.
3. Choose “Empty Activity” and click Next.
4. Enter the project name: SimpleInvoiceApp
5. Set the language to Java.
6. Click Finish to create the project.
4. Designing the Layout (XML)
1. Open res/layout/activity_main.xml
2. Replace the content with the following XML:
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white"
android:padding="20dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="50dp"
android:text="Simple Invoice App" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Item Name"
android:textSize="23sp"
android:id="@+id/edtName"
android:inputType="text"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Unit Price"
android:id="@+id/edtPrice"
android:textSize="23sp"
android:inputType="numberDecimal"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Quantity"
android:textSize="23sp"
android:id="@+id/edtQty"
android:inputType="number"
android:layout_marginTop="20dp" />
<Button
android:layout_width="match_parent"
android:text="Add Item"
android:gravity="center"
android:id="@+id/btnAdd"
android:textSize="25sp"
android:textStyle="bold"
android:background="#ccc"
android:layout_marginTop="20dp"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/lvItems"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
[Insert Screenshot Here: Layout Preview]
5. Writing the Java Code
1. Open MainActivity.java in the java folder.
2. Replace the code with the following:
package com.example.invoiceapp;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
EditText edtName, edtPrice, edtQty;
Button btnAdd;
ListView lvItems;
TextView txtTotal;
ArrayList<String> itemList;
ArrayAdapter<String> adapter;
double overallTotal = 0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtName = findViewById(R.id.edtName);
edtPrice = findViewById(R.id.edtPrice);
edtQty = findViewById(R.id.edtQty);
btnAdd = findViewById(R.id.btnAdd);
lvItems = findViewById(R.id.lvItems);
txtTotal = new TextView(this);
txtTotal.setTextSize(20);
txtTotal.setPadding(20, 20, 20, 20);
lvItems.addFooterView(txtTotal);
itemList = new ArrayList<>();
adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, itemList);
lvItems.setAdapter(adapter);
btnAdd.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
String name =
edtName.getText().toString().trim();
String priceStr =
edtPrice.getText().toString().trim();
String qtyStr =
edtQty.getText().toString().trim();
if (name.isEmpty() || priceStr.isEmpty() ||
qtyStr.isEmpty()) {
Toast.makeText(MainActivity.this,
"Please fill all fields", Toast.LENGTH_SHORT).show();
return;
}
double price = Double.parseDouble(priceStr);
int qty = Integer.parseInt(qtyStr);
double total = price * qty;
overallTotal += total;
String item = "Item: " + name + ", Unit
Price: " + price + ", Qty: " + qty + ", Total: " + total;
itemList.add(item);
adapter.notifyDataSetChanged();
txtTotal.setText("Overall Total: " +
overallTotal);
edtName.setText("");
edtPrice.setText("");
edtQty.setText("");
}
});
}
}
6. Run the App
1. Connect your Android device or start an emulator.
2. Click the green Run button.
3. The app will launch. Enter item name, unit price, and quantity, then click Add Item.
4. Items will show up in the list with their totals.
5. The overall total is displayed below the list.
7. Conclusion
You have successfully built a simple invoice app that takes user input, calculates item
totals, and shows an overall total. This is a great foundation for developing more complex
inventory or billing applications.
Notes:
• Make sure your phone has Developer Mode enabled for testing.
• You can enhance the app by saving data using SQLite or SharedPreferences.
• Explore ways to delete or edit items in the list.
Step-by-Step Guide: Creating a Simple Todo
List App in Android Studio
Target Audience: Beginner students learning Android App Development App Name:
Simple Todo List App
1. Introduction
In this handout, you will learn how to create a simple Todo List app using Android Studio.
The app allows users to enter an item name and then adds the item to a list on Add button
click.
2. Tools Needed
• Android Studio (latest version recommended)
• Java Development Kit (JDK)
• Basic knowledge of XML and Java
3. Project Setup
6. Open Android Studio.
7. Click on “New Project”.
8. Choose “Empty Activity” and click Next.
9. Enter the project name: SimpleTodoListApp
10. Set the language to Java.
11. Click Finish to create the project.
4. Designing the Layout (XML)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/andro
id"
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"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="ToDo List"
android:textSize="34sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/edtAddItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:gravity="start|top"
android:hint="Add Item..."
android:inputType="textMultiLine" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ADD" />
</LinearLayout>
<ListView
android:id="@+id/lvListItems"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
5. Writing the Java Code
1. Open MainActivity.java in the java folder.
2. Replace the code with the following:
package com.example.todolist;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
//Variable declarations
EditText edtAddItem;
Button btnAdd;
ListView lvItemList;
ArrayList<String> itemList;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Setting an instances of the various objects
edtAddItem = (EditText)
findViewById(R.id.edtAddItem);
btnAdd = (Button) findViewById(R.id.btnAdd);
lvItemList = (ListView)
findViewById(R.id.lvListItems);
itemList = new ArrayList<>();
adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, itemList);
// Set the Listview Adapter
lvItemList.setAdapter(adapter);
//Set when the user clicks on the button
btnAdd.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
//Get the user inputs
String item =
edtAddItem.getText().toString();
//Check if the input is empty
if(item.isEmpty()){
//Display a message to the user
Toast.makeText(MainActivity.this,
"Item cannot be empty", Toast.LENGTH_LONG).show();
}else {
//Add the inputs to the array list
itemList.add(item);
//Notify the adapter that there is
a change in list(When a new item is added)
adapter.notifyDataSetChanged();
//Clear the textbox
edtAddItem.setText("");
}
}
});
//When the user long clicks on an item
lvItemList.setOnItemLongClickListener(new
AdapterView.OnItemLongClickListener() {
@Override
public boolean
onItemLongClick(AdapterView<?> parent, View view, int
position, long id) {
//Remove the selected item from the
array list using it position
itemList.remove(position);
//Notify the adapter that there is a
change
adapter.notifyDataSetChanged();
return true;
}
});
}
}
6. Run the App
1. Connect your Android device or start an emulator.
2. Click the green Run button.
3. The app will launch. Enter item name, unit price, and quantity, then click Add Item.
4. Items will show up in the list with their totals.
5. The overall total is displayed below the list.
7. Conclusion
You have successfully built a simple Todo List app that takes user input. This is a great
foundation for developing more complex Todo List applications.
Notes:
• Make sure your phone has Developer Mode enabled for testing.
• You can enhance the app by saving data using SQLite or SharedPreferences.
• Explore ways to delete or edit items in the list.
End of Handout