ListView Examples. Basic Steps for Creating a Listview 1.Create a layout (e.g., a LinearLayout), with elements for –the ListView (

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 6 Overview Programming Tutorial 3: Sending/Receiving SMS Messages.
Advertisements

Programming with Android: Data management
Section 2.5 Single-Linked Lists. A linked list is useful for inserting and removing at arbitrary locations The ArrayList is limited because its add and.
Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
Ics202 Data Structures. hh tail head (b) LinkedList head tail Element datum next 3 Integer Element datum next 1 Integer Element datum next 4 Integer.
Android – CoNTENT PRoViders
ContentProviders.  Databases for reading & writing data  Support typical database operations  e.g., query, insert, update & delete.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
CONTENT PROVIDER. Content Provider  A content provider makes a specific set of the application's data available to other applications => Share data to.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
CS378 - Mobile Computing Persistence - SQLite. Databases RDBMS – relational data base management system Relational databases introduced by E. F. Codd.
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Android: Layouts David Meredith
Data Storage: Part 1 (Preferences)
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
COSC 2007 Data Structures II
Data Storage: Part 3 (SQLite)
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College.
CSCI 6962: Server-side Design and Programming Support Classes and Shopping Carts.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
Content providers Accessing shared data in a uniform way 1Content providers.
Cosc 5/4730 Android Content Providers and Intents.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
Package org.androidtown.database.query; import android.app.Activity; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Mobile Computing Lecture#11 Adapters and Dialogs.
Address Book App 1. Define styles   Specify a background for a TextView – res/drawable/textview_border.xml.
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
User Interfaces: Part 1 (View Groups and Layouts).
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. An application.
CSC1401 Classes - 1. Learning Goals Computing concepts Identifying objects and classes Declaring a class Declaring fields Default field values.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Copyright© Jeffrey Jongko, Ateneo de Manila University Custom ListAdapters.
Persistence Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Video Games list lab 6  At the end of this lab you will be expected to know:  What Views, View Groups, Layouts, and Widgets are and how they relate to.
ListView and ExpandableListView
Cosc 4735 Activities, fragments, callbacks/listeners/interfaces.
Address Book App 1 Fall 2014 CS7020: Game Design and Development.
David Sutton USING CONTENT PROVIDERS. TOPICS COVERED THIS WEEK  Persistence  Introduction to databases  Content providers  Cursors  Cursor adapters.
CHAPTER 9 File Storage Shared Preferences SQLite.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
Database Programming Code Dissection. Layered Approach Presentation (Activity) DbSampleActivity.java DataAccess (DataSource) CommentsDataSource.java MySQLiteHelper.java.
Content Providers.
Making content providers
Content provider.
Data Storage: Part 4 (Content Providers)
Content Providers And Content Resolvers
GUI Programming Fundamentals
ListView: Part 2.
Android Application SQLite 1.
CS2006- Data Structures I Chapter 5 Linked Lists I.
Concurrency in Android
CS499 – Mobile Application Development
Mobile Application Development Chapter 5 [Persistent Data in Android]
Content Providers.
Android Programming Lecture 6
ANDROID LISTS.
Android Lists and Fragments
Mobile Computing With Android ACST 4550 Android Database Storage
Android Developer Fundamentals V2
HNDIT2417 Mobile Application Development
Android Developer Fundamentals V2
ListView ? BaseAdapter ?.
ListView A view that shows items in a vertically scrolling list. The items come from the ListAdapter associated with this view. ListAdapter is used to.
plus content providers, loaders, recyclerview
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

ListView Examples

Basic Steps for Creating a Listview 1.Create a layout (e.g., a LinearLayout), with elements for –the ListView ( ) –the TextView ( ) –Other, e.g., a button to add a new item to the list 2.Create a layout for each item in the list (e.g., separate TextView for each field) 3.Implement the main activity (see following slides) Slide 2©SoftMoore Consulting

Implementing the Main Activity Declare that the main activity implements LoaderManager.LoaderCallbacks onCreateLoader(int id, Bundle args) onLoadFinished(Loader loader, D data) onLoaderReset(Loader loader) Decide which columns in the content provider get mapped to which views in the item layout private static final String[] VIEW_COLUMNS = { "name", "phone_num" }; private static final int[] VIEWS = { R.id.name, R.id.phoneNum }; Implement method onCreate() Implement other methods; e.g., onListItemClick(ListView l, View v, int position, long id) Slide 3©SoftMoore Consulting

Implementing public Loader onCreateLoader(int id, Bundle args) { Uri uri =... ; // CONTENT_URI; return new CursorLoader(this, uri, COLUMNS, null, null, null); public void onLoadFinished(Loader loader, Cursor data) { adapter.swapCursor(data); public void onLoaderReset(Loader loader) { adapter.swapCursor(null); } Slide 4©SoftMoore Consulting

Implementing the onCreate() Method Create an empty adapter for displaying the loaded data adapter = new SimpleCursorAdapter(this, R.layout.emergency_contact, null, VIEW_COLUMNS, VIEWS, 0); setListAdapter(adapter); Set up other listeners; e.g., –setOnItemLongClickListener() // delete item from list –setOnClickListener() // for button to add new item to list Initialize the loader manager in the activity’s onCreate() method. getLoaderManager().initLoader(0, null, this); Slide 5©SoftMoore Consulting Note: Need API level 11 or higher for SimpleCursorAdapter ’s constructor. these columns get mapped to these views

Advantages of Using Loaders They are available to every Activity and Fragment. They provide asynchronous loading of data. They monitor the source of their data and deliver new results when the content changes. They automatically reconnect to the last loader’s cursor when being recreated after a configuration change; i.e., they don't need to re-query their data. Slide 6©SoftMoore Consulting

Emergency Contacts (from Simple Database) Slide 7©SoftMoore Consulting

Contacts with Phone Numbers (Redacted) Slide 8©SoftMoore Consulting

Discussion See Handouts Main Activity for Emergency Contacts –uses a simple SQLite database Main Activity for Contacts with Phone Numbers –uses contacts provider –note use of adapter.setViewBinder to convert contact phone types (integers) into strings Slide 9©SoftMoore Consulting

Relevant Links List View Retrieving a List of Contacts Loaders Understanding the LoaderManager (part 2) Making ListView Scrolling Smooth Slide 10©SoftMoore Consulting