SlideShare a Scribd company logo
Welcome!
Today we are going
to create a new
Android Application
from scratch.
Create a new
Android Project with
a name ToDoList
If you have problems, look through
previous tutorial.
Modify the main layout (activity_main.xml in /res/layout)
to include ListView, Button and EditText within a
LinearLayout.
<?xml version= "1.0" encoding = "utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New To Do Item" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text = "Add" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Its important to give Button, EditText and ListView
controls IDs so you can get reference to them in the
code.
<?xml version= "1.0" encoding = "utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent">
<EditText
android:id = "@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New To Do Item" />
<Button
android:id = "@+id/buttonAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text = "Add" />
<ListView
android:id = "@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Now open your main Activity class (MainActivity.java at
/ src / com. … / ).
Default main activity prob looks like:
package com.example.todolist;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Takes layout from
resource folder we
have made recently.
We will work only with onCreate method. Firstly get
references to the ListView and EditText using
findViewById.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate activity view
setContentView(R.layout.activity_main);
// Get reference to UI
ListView myListView = (ListView)findViewById(R.id.listView);
EditText myEditText = (EditText)findViewById(R.id.editText);
Button buttonAdd = (Button)findViewById(R.id.buttonAdd);
}
Now we need to create ArrayList of Strings to store
each to-do list item. (check out about array list if you are not sure)
And ArrayAdapter to store content in ListView.
(check out about array list if you are not sure)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate activity view
setContentView(R.layout.activity_main);
// Get reference to UI
ListView myListView = (ListView)findViewById(R.id.listView);
EditText myEditText = (EditText)findViewById(R.id.editText);
Button buttonAdd = (Button)findViewById(R.id.buttonAdd);
// Create the array list of to-do items
ArrayList<String> todoItems = new ArrayList<String>();
// Create the array adapter to bind the array to the listview
ArrayAdapter<String> aa;
}
Next step to bind string array with array adapter and
with listView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate activity view
setContentView(R.layout.activity_main);
// Get reference to UI
ListView myListView = (ListView)findViewById(R.id.listView);
EditText myEditText = (EditText)findViewById(R.id.editText);
Button buttonAdd = (Button)findViewById(R.id.buttonAdd);
// Create the array list of to-do items
ArrayList<String> todoItems = new ArrayList<String>();
// Create the array adapter to bind the array to the listview
ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
todoItems);
// Bind the array adapter to the listView
myListView.setAdapter(aa);
}
Defining array
adapter through
current object,
layout item and
array list.
The final step is to make to-do list functional.
Add onKeyListener to the EditText that listens for a
“D-pad center button” and add item to string array list.
Add final label for
variables used inside
OnKeyListner to make
sure they won't going
to change
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate activity view
setContentView(R.layout.activity_main);
// Get reference to UI
ListView myListView = (ListView)findViewById(R.id.listView);
final EditText myEditText =
(EditText)findViewById(R.id.editText);
final Button buttonAdd = (Button)findViewById(R.id.buttonAdd);
// Create the array list of to-do items
final ArrayList<String> todoItems = new ArrayList<String>();
// Create the array adapter to bind the array to the listview
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
todoItems);
// Bind the array adapter to the listView
myListView.setAdapter(aa);
buttonAdd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
todoItems.add(0, myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText("");
}
});
}
Run your application.
You should get something
like:
If you have problems check code on github:
(check out, if you are not sure about Github)
Or text me if you found any mistakes or you
want to add something to presentation:

More Related Content

Viewers also liked (20)

PDF
Yourprezi
rogernoratoromero
 
PPTX
Reliable Drupal Partner
AddWeb Solution Pvt. Ltd.
 
PDF
DOL model notice for exchange
Jerry Whitaker CIC,CRIS
 
PPTX
The asian section collections final
Asiansection
 
PPTX
Услуги стадиона «Динамо»
Andrey Pantiukhov
 
PPT
68788 health care reform health plans overview 2 14-13
Jerry Whitaker CIC,CRIS
 
PPTX
Ainu talk manuscripts - final
Asiansection
 
PPTX
Dairyfree
Missdip24
 
PPTX
Uniforme scolare
Hainute copii Johnny Prodcomimpex
 
PPTX
Cr chap 4
mll11e
 
PPTX
Dairyfree
Missdip24
 
PDF
Clink for Card Issuers
Roshan Gummalla
 
ODP
Github tutorial1
Vlad Kolesnyk
 
PDF
Wasicunwitkotko
ales fiala
 
DOCX
Classroom Management
Ramil Gallardo
 
PDF
Yourprezi
rogernoratoromero
 
PPTX
Foodcombining visuals
Missdip24
 
Reliable Drupal Partner
AddWeb Solution Pvt. Ltd.
 
DOL model notice for exchange
Jerry Whitaker CIC,CRIS
 
The asian section collections final
Asiansection
 
Услуги стадиона «Динамо»
Andrey Pantiukhov
 
68788 health care reform health plans overview 2 14-13
Jerry Whitaker CIC,CRIS
 
Ainu talk manuscripts - final
Asiansection
 
Dairyfree
Missdip24
 
Cr chap 4
mll11e
 
Dairyfree
Missdip24
 
Clink for Card Issuers
Roshan Gummalla
 
Github tutorial1
Vlad Kolesnyk
 
Wasicunwitkotko
ales fiala
 
Classroom Management
Ramil Gallardo
 
Foodcombining visuals
Missdip24
 

Similar to Android tutorials8 todo_list (20)

PDF
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
DOC
Android Application DevlopmentManual-1.doc
KiranmaiBejjam1
 
PDF
Android por onde começar? Mini Curso Erbase 2015
Mario Jorge Pereira
 
PPTX
ListView and Custom ListView on Android Development [Thai]
Somkiat Khitwongwattana
 
PDF
Tutorial basicapp
Herry Prasetyo
 
PDF
Custom UI Components at Android Only 2011
Johan Nilsson
 
DOC
Android App Dev Manual-1.doc
SriKGangadharRaoAssi
 
DOCX
Layout
deepikasony
 
PPTX
What's New in Android
Robert Cooper
 
ODP
Session 2- day 3
Vivek Bhusal
 
PDF
List Views
Ahsanul Karim
 
PPT
View groups containers
Mani Selvaraj
 
PPTX
How to Use ReorderableListView Widget in Flutter App Development.pptx
RubenGray1
 
DOCX
Android list view tutorial by Javatechig
Javatechig Resources for Developers
 
PPTX
Android 3
Robert Cooper
 
PPTX
chp 4 UI component hdjdjdduudfinalt.pptx
Good490110
 
PDF
Android crashcourse
Alexey Buzdin
 
DOCX
List view languages
university of Gujrat, pakistan
 
PDF
Android L01 - Warm Up
Mohammad Shaker
 
PDF
How to become an Android dev starting from iOS (and vice versa)
Giuseppe Filograno
 
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Android Application DevlopmentManual-1.doc
KiranmaiBejjam1
 
Android por onde começar? Mini Curso Erbase 2015
Mario Jorge Pereira
 
ListView and Custom ListView on Android Development [Thai]
Somkiat Khitwongwattana
 
Tutorial basicapp
Herry Prasetyo
 
Custom UI Components at Android Only 2011
Johan Nilsson
 
Android App Dev Manual-1.doc
SriKGangadharRaoAssi
 
Layout
deepikasony
 
What's New in Android
Robert Cooper
 
Session 2- day 3
Vivek Bhusal
 
List Views
Ahsanul Karim
 
View groups containers
Mani Selvaraj
 
How to Use ReorderableListView Widget in Flutter App Development.pptx
RubenGray1
 
Android list view tutorial by Javatechig
Javatechig Resources for Developers
 
Android 3
Robert Cooper
 
chp 4 UI component hdjdjdduudfinalt.pptx
Good490110
 
Android crashcourse
Alexey Buzdin
 
List view languages
university of Gujrat, pakistan
 
Android L01 - Warm Up
Mohammad Shaker
 
How to become an Android dev starting from iOS (and vice versa)
Giuseppe Filograno
 
Ad

More from Vlad Kolesnyk (11)

ODP
Mobile andwebapps
Vlad Kolesnyk
 
ODP
Mech eng presentation
Vlad Kolesnyk
 
ODP
Android tutorials7 calculator_intro
Vlad Kolesnyk
 
ODP
Android tutorials6 run_your_app
Vlad Kolesnyk
 
ODP
Android tutorials7 calculator
Vlad Kolesnyk
 
ODP
Android tutorials2 android_tools_on_eclipse
Vlad Kolesnyk
 
ODP
Android tutorials1 install_ide
Vlad Kolesnyk
 
ODP
Android tutorials7 calculator_packageexploirer
Vlad Kolesnyk
 
ODP
Android tutorials7 calculator_basiclayout
Vlad Kolesnyk
 
ODP
Android tutorials7 calculator_javaprogramming
Vlad Kolesnyk
 
ODP
Android tutorials7 calulator_improve
Vlad Kolesnyk
 
Mobile andwebapps
Vlad Kolesnyk
 
Mech eng presentation
Vlad Kolesnyk
 
Android tutorials7 calculator_intro
Vlad Kolesnyk
 
Android tutorials6 run_your_app
Vlad Kolesnyk
 
Android tutorials7 calculator
Vlad Kolesnyk
 
Android tutorials2 android_tools_on_eclipse
Vlad Kolesnyk
 
Android tutorials1 install_ide
Vlad Kolesnyk
 
Android tutorials7 calculator_packageexploirer
Vlad Kolesnyk
 
Android tutorials7 calculator_basiclayout
Vlad Kolesnyk
 
Android tutorials7 calculator_javaprogramming
Vlad Kolesnyk
 
Android tutorials7 calulator_improve
Vlad Kolesnyk
 
Ad

Recently uploaded (20)

PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and...
AWS Chicago
 
July Patch Tuesday
Ivanti
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 

Android tutorials8 todo_list

  • 2. Today we are going to create a new Android Application from scratch.
  • 3. Create a new Android Project with a name ToDoList If you have problems, look through previous tutorial.
  • 4. Modify the main layout (activity_main.xml in /res/layout) to include ListView, Button and EditText within a LinearLayout. <?xml version= "1.0" encoding = "utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent"> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="New To Do Item" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text = "Add" /> <ListView android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
  • 5. Its important to give Button, EditText and ListView controls IDs so you can get reference to them in the code. <?xml version= "1.0" encoding = "utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent"> <EditText android:id = "@+id/editText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="New To Do Item" /> <Button android:id = "@+id/buttonAdd" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text = "Add" /> <ListView android:id = "@+id/listView" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
  • 6. Now open your main Activity class (MainActivity.java at / src / com. … / ). Default main activity prob looks like: package com.example.todolist; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } Takes layout from resource folder we have made recently.
  • 7. We will work only with onCreate method. Firstly get references to the ListView and EditText using findViewById. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate activity view setContentView(R.layout.activity_main); // Get reference to UI ListView myListView = (ListView)findViewById(R.id.listView); EditText myEditText = (EditText)findViewById(R.id.editText); Button buttonAdd = (Button)findViewById(R.id.buttonAdd); }
  • 8. Now we need to create ArrayList of Strings to store each to-do list item. (check out about array list if you are not sure) And ArrayAdapter to store content in ListView. (check out about array list if you are not sure) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate activity view setContentView(R.layout.activity_main); // Get reference to UI ListView myListView = (ListView)findViewById(R.id.listView); EditText myEditText = (EditText)findViewById(R.id.editText); Button buttonAdd = (Button)findViewById(R.id.buttonAdd); // Create the array list of to-do items ArrayList<String> todoItems = new ArrayList<String>(); // Create the array adapter to bind the array to the listview ArrayAdapter<String> aa; }
  • 9. Next step to bind string array with array adapter and with listView @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate activity view setContentView(R.layout.activity_main); // Get reference to UI ListView myListView = (ListView)findViewById(R.id.listView); EditText myEditText = (EditText)findViewById(R.id.editText); Button buttonAdd = (Button)findViewById(R.id.buttonAdd); // Create the array list of to-do items ArrayList<String> todoItems = new ArrayList<String>(); // Create the array adapter to bind the array to the listview ArrayAdapter<String> aa; aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, todoItems); // Bind the array adapter to the listView myListView.setAdapter(aa); } Defining array adapter through current object, layout item and array list.
  • 10. The final step is to make to-do list functional. Add onKeyListener to the EditText that listens for a “D-pad center button” and add item to string array list. Add final label for variables used inside OnKeyListner to make sure they won't going to change @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate activity view setContentView(R.layout.activity_main); // Get reference to UI ListView myListView = (ListView)findViewById(R.id.listView); final EditText myEditText = (EditText)findViewById(R.id.editText); final Button buttonAdd = (Button)findViewById(R.id.buttonAdd); // Create the array list of to-do items final ArrayList<String> todoItems = new ArrayList<String>(); // Create the array adapter to bind the array to the listview final ArrayAdapter<String> aa; aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, todoItems); // Bind the array adapter to the listView myListView.setAdapter(aa); buttonAdd.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub todoItems.add(0, myEditText.getText().toString()); aa.notifyDataSetChanged(); myEditText.setText(""); } }); }
  • 11. Run your application. You should get something like:
  • 12. If you have problems check code on github: (check out, if you are not sure about Github) Or text me if you found any mistakes or you want to add something to presentation: