SlideShare una empresa de Scribd logo
1 de 11
Welcome!
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:

Más contenido relacionado

La actualidad más candente

Petros Plakogiannis - Exploratory testing with browser console
Petros Plakogiannis - Exploratory testing with browser consolePetros Plakogiannis - Exploratory testing with browser console
Petros Plakogiannis - Exploratory testing with browser consolePetrosPlakogiannis
 
How to Create a Parameter Set on Aeros LIVE
How to Create a Parameter Set on Aeros LIVEHow to Create a Parameter Set on Aeros LIVE
How to Create a Parameter Set on Aeros LIVECultura Technologies
 
今10年経って〜思うことあれこれ〜 hasegawa
今10年経って〜思うことあれこれ〜 hasegawa今10年経って〜思うことあれこれ〜 hasegawa
今10年経って〜思うことあれこれ〜 hasegawaalis_lib
 

La actualidad más candente (7)

Petros Plakogiannis - Exploratory testing with browser console
Petros Plakogiannis - Exploratory testing with browser consolePetros Plakogiannis - Exploratory testing with browser console
Petros Plakogiannis - Exploratory testing with browser console
 
Android app
Android appAndroid app
Android app
 
Use sqlite
Use sqliteUse sqlite
Use sqlite
 
How to Create a Parameter Set on Aeros LIVE
How to Create a Parameter Set on Aeros LIVEHow to Create a Parameter Set on Aeros LIVE
How to Create a Parameter Set on Aeros LIVE
 
App C
App CApp C
App C
 
今10年経って〜思うことあれこれ〜 hasegawa
今10年経って〜思うことあれこれ〜 hasegawa今10年経って〜思うことあれこれ〜 hasegawa
今10年経って〜思うことあれこれ〜 hasegawa
 
Ensayo
EnsayoEnsayo
Ensayo
 

Destacado

Mech eng presentation
Mech eng presentationMech eng presentation
Mech eng presentationVlad Kolesnyk
 
Doing things with manuscripts: CLIR post doc-seminar, Bryn Mawr College 7.31....
Doing things with manuscripts: CLIR post doc-seminar, Bryn Mawr College 7.31....Doing things with manuscripts: CLIR post doc-seminar, Bryn Mawr College 7.31....
Doing things with manuscripts: CLIR post doc-seminar, Bryn Mawr College 7.31....SNichols4
 
How the cell phone work
How the cell phone workHow the cell phone work
How the cell phone workcollatus12
 
Android tutorials6 run_your_app
Android tutorials6 run_your_appAndroid tutorials6 run_your_app
Android tutorials6 run_your_appVlad Kolesnyk
 
Foodcombining visuals
Foodcombining visualsFoodcombining visuals
Foodcombining visualsMissdip24
 
Angela Ayois: Twitter for Teaching Corporate Social Responsibility
Angela Ayois: Twitter for Teaching Corporate Social ResponsibilityAngela Ayois: Twitter for Teaching Corporate Social Responsibility
Angela Ayois: Twitter for Teaching Corporate Social ResponsibilityChris Evans
 
Android tutorials7 calculator_basiclayout
Android tutorials7 calculator_basiclayoutAndroid tutorials7 calculator_basiclayout
Android tutorials7 calculator_basiclayoutVlad Kolesnyk
 
Cr chap 4
Cr chap 4Cr chap 4
Cr chap 4mll11e
 
Услуги стадиона «Динамо»
Услуги стадиона «Динамо»Услуги стадиона «Динамо»
Услуги стадиона «Динамо»Andrey Pantiukhov
 
Ray Kirby: Lectures are STILL Appropriate
Ray Kirby: Lectures are STILL AppropriateRay Kirby: Lectures are STILL Appropriate
Ray Kirby: Lectures are STILL AppropriateChris Evans
 

Destacado (20)

Construction Risk Management ABC's
Construction Risk Management ABC'sConstruction Risk Management ABC's
Construction Risk Management ABC's
 
Yourprezi
YourpreziYourprezi
Yourprezi
 
Mobile andwebapps
Mobile andwebappsMobile andwebapps
Mobile andwebapps
 
Brief about outsourcing
Brief about outsourcingBrief about outsourcing
Brief about outsourcing
 
Mech eng presentation
Mech eng presentationMech eng presentation
Mech eng presentation
 
Doing things with manuscripts: CLIR post doc-seminar, Bryn Mawr College 7.31....
Doing things with manuscripts: CLIR post doc-seminar, Bryn Mawr College 7.31....Doing things with manuscripts: CLIR post doc-seminar, Bryn Mawr College 7.31....
Doing things with manuscripts: CLIR post doc-seminar, Bryn Mawr College 7.31....
 
How the cell phone work
How the cell phone workHow the cell phone work
How the cell phone work
 
Android tutorials6 run_your_app
Android tutorials6 run_your_appAndroid tutorials6 run_your_app
Android tutorials6 run_your_app
 
Patient safety program scd
Patient safety program scdPatient safety program scd
Patient safety program scd
 
Yourprezi
YourpreziYourprezi
Yourprezi
 
Teks Forum Hegemoni
Teks Forum HegemoniTeks Forum Hegemoni
Teks Forum Hegemoni
 
Benefits 101 guide
Benefits 101 guideBenefits 101 guide
Benefits 101 guide
 
Foodcombining visuals
Foodcombining visualsFoodcombining visuals
Foodcombining visuals
 
Angela Ayois: Twitter for Teaching Corporate Social Responsibility
Angela Ayois: Twitter for Teaching Corporate Social ResponsibilityAngela Ayois: Twitter for Teaching Corporate Social Responsibility
Angela Ayois: Twitter for Teaching Corporate Social Responsibility
 
Android tutorials7 calculator_basiclayout
Android tutorials7 calculator_basiclayoutAndroid tutorials7 calculator_basiclayout
Android tutorials7 calculator_basiclayout
 
Woolley final presentation
Woolley final presentationWoolley final presentation
Woolley final presentation
 
Cr chap 4
Cr chap 4Cr chap 4
Cr chap 4
 
Услуги стадиона «Динамо»
Услуги стадиона «Динамо»Услуги стадиона «Динамо»
Услуги стадиона «Динамо»
 
Final
FinalFinal
Final
 
Ray Kirby: Lectures are STILL Appropriate
Ray Kirby: Lectures are STILL AppropriateRay Kirby: Lectures are STILL Appropriate
Ray Kirby: Lectures are STILL Appropriate
 

Similar a Create Android ToDo List App with ListView and ArrayAdapter

Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsAhsanul Karim
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Mario Jorge Pereira
 
Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Johan Nilsson
 
ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]Somkiat Khitwongwattana
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in AndroidRobert Cooper
 
View groups containers
View groups containersView groups containers
View groups containersMani Selvaraj
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your appsJuan C Catalan
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)Giuseppe Filograno
 
How to Use ReorderableListView Widget in Flutter App Development.pptx
How to Use ReorderableListView Widget in Flutter App Development.pptxHow to Use ReorderableListView Widget in Flutter App Development.pptx
How to Use ReorderableListView Widget in Flutter App Development.pptxFlutter Agency
 
Building a Mobile App with Sencha Touch
Building a Mobile App with Sencha TouchBuilding a Mobile App with Sencha Touch
Building a Mobile App with Sencha TouchJames Pearce
 

Similar a Create Android ToDo List App with ListView and ArrayAdapter (20)

Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
 
Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011
 
Tutorial basicapp
Tutorial basicappTutorial basicapp
Tutorial basicapp
 
Android App Dev Manual-1.doc
Android App Dev Manual-1.docAndroid App Dev Manual-1.doc
Android App Dev Manual-1.doc
 
ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 
Session 2- day 3
Session 2- day 3Session 2- day 3
Session 2- day 3
 
Android 3
Android 3Android 3
Android 3
 
Android crashcourse
Android crashcourseAndroid crashcourse
Android crashcourse
 
View groups containers
View groups containersView groups containers
View groups containers
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your apps
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)
 
How to Use ReorderableListView Widget in Flutter App Development.pptx
How to Use ReorderableListView Widget in Flutter App Development.pptxHow to Use ReorderableListView Widget in Flutter App Development.pptx
How to Use ReorderableListView Widget in Flutter App Development.pptx
 
Layout
LayoutLayout
Layout
 
Android programming basics
Android programming basicsAndroid programming basics
Android programming basics
 
List Views
List ViewsList Views
List Views
 
Building a Mobile App with Sencha Touch
Building a Mobile App with Sencha TouchBuilding a Mobile App with Sencha Touch
Building a Mobile App with Sencha Touch
 
List view languages
List view languagesList view languages
List view languages
 

Más de Vlad Kolesnyk

Android tutorials7 calculator_intro
Android tutorials7 calculator_introAndroid tutorials7 calculator_intro
Android tutorials7 calculator_introVlad Kolesnyk
 
Android tutorials7 calculator
Android tutorials7 calculatorAndroid tutorials7 calculator
Android tutorials7 calculatorVlad Kolesnyk
 
Android tutorials2 android_tools_on_eclipse
Android tutorials2 android_tools_on_eclipseAndroid tutorials2 android_tools_on_eclipse
Android tutorials2 android_tools_on_eclipseVlad Kolesnyk
 
Android tutorials1 install_ide
Android tutorials1 install_ideAndroid tutorials1 install_ide
Android tutorials1 install_ideVlad Kolesnyk
 
Android tutorials7 calculator_packageexploirer
Android tutorials7 calculator_packageexploirerAndroid tutorials7 calculator_packageexploirer
Android tutorials7 calculator_packageexploirerVlad Kolesnyk
 
Android tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogrammingAndroid tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogrammingVlad Kolesnyk
 
Android tutorials7 calulator_improve
Android tutorials7 calulator_improveAndroid tutorials7 calulator_improve
Android tutorials7 calulator_improveVlad Kolesnyk
 

Más de Vlad Kolesnyk (8)

Android tutorials7 calculator_intro
Android tutorials7 calculator_introAndroid tutorials7 calculator_intro
Android tutorials7 calculator_intro
 
Android tutorials7 calculator
Android tutorials7 calculatorAndroid tutorials7 calculator
Android tutorials7 calculator
 
Android tutorials2 android_tools_on_eclipse
Android tutorials2 android_tools_on_eclipseAndroid tutorials2 android_tools_on_eclipse
Android tutorials2 android_tools_on_eclipse
 
Android tutorials1 install_ide
Android tutorials1 install_ideAndroid tutorials1 install_ide
Android tutorials1 install_ide
 
Android tutorials7 calculator_packageexploirer
Android tutorials7 calculator_packageexploirerAndroid tutorials7 calculator_packageexploirer
Android tutorials7 calculator_packageexploirer
 
Android tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogrammingAndroid tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogramming
 
Android tutorials7 calulator_improve
Android tutorials7 calulator_improveAndroid tutorials7 calulator_improve
Android tutorials7 calulator_improve
 
Github tutorial1
Github tutorial1Github tutorial1
Github tutorial1
 

Último

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Create Android ToDo List App with ListView and ArrayAdapter

  • 2. Create a new Android Project with a name ToDoList If you have problems, look through previous tutorial.
  • 3. 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>
  • 4. 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>
  • 5. 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.
  • 6. 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); }
  • 7. 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; }
  • 8. 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.
  • 9. 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(""); } }); }
  • 10. Run your application. You should get something like:
  • 11. 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: