Copyright© Jeffrey Jongko, Ateneo de Manila University Custom ListAdapters.

Slides:



Advertisements
Similar presentations
Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from.
Advertisements

Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
Programming with Android: Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
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
Android UI, and Networking. Can do most networking on Android Bluetooth only on 2.0, Not supported with version 1.6.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Introducing the Sudoku Example
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Android Layouts. Layouts Define the user interface for an activity Layouts are defined in.xml files – within /res/layout folder – different layout can.
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Mobile Programming Lecture 6
Resources and RelativeLayouts. Resources Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type.
CE Applied Communications Technology Android lecture 2 - Structures Android File structure Resources Drawables Layout Values R Class Manifest Running.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
Mobile Computing Lecture#11 Adapters and Dialogs.
ListView.
Create Navigation Drawer Team 2 Zhong Wang Jiaming Dong Philip Wu Lingduo Kong.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 7: Reveal! Displaying Pictures in a GridView.
User Interfaces: Part 1 (View Groups and Layouts).
Chapter 7: Reveal! Displaying Pictures in a Gallery.
Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.
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 Editing ListAdapter Data part 2.
DKU-MUST Mobile ICT Education Center 11. AdapterView.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
ListView and ExpandableListView
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
Packages. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L13: Layout Managers Slide 2.
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
Building User Interfaces Basic Applications
More App Customizations. Overview  Application/ Activity Customizations: Themes  Menu Customizations  Custom Dialogs  Custom Toasts  Custom Buttons.
Building UI Components Димитър Н. Димитров Astea Solutions AD.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Lab7 – Appendix.
CS499 – Mobile Application Development
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Further android gui programming
ListView: Part 2.
Customizaiton of Layouts
Android Widgets 1 7 August 2018
ITEC535 – Mobile Programming
android architecture components with mvvm
ANDROID UI – FRAGMENTS UNIT II.
Android Programming Lecture 6
CIS 470 Mobile App Development
Android Lists and Fragments
CA16R405 - Mobile Application Development (Theory)
Building User Interfaces Basic Applications
Android Topics Custom ArrayAdapters
Android Topics Custom ArrayAdapters Creating an Event Listener
Android Developer Fundamentals V2 Lesson 4
Android Topics Limited Resources and why we need to consider them.
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
ListView ? BaseAdapter ?.
Reactive Android Development
Korea Software HRD Center
Activities and Fragments
CS 240 – Advanced Programming Concepts
Lasalle-App Tecnología Móvil.
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Copyright© Jeffrey Jongko, Ateneo de Manila University Custom ListAdapters

ListAdapter  Acts as the bridge between a ListView and the data that backs the list (the model)ListView  Interface found in android.widget package  Several subtypes are built-in to android

Custom ListAdapters  The true power of the ListView/ ListAdapter combination is the ability to define your own ListAdapter to best suit you application  ListAdapter is simply an interface that needs to be implemented

ListAdapter interface  ListAdapter contains several methods inside it that need to be implemented  Some methods: public int getCount() - returns the number of items public Object getItem(int arg0) – returns the object at a given position public long getItemId(int position) – return a unique ID for a given position

ListAdapter interface public View getView(int position, View convertView, ViewGroup parent) – returns a view object used to render the data  convertView represents an existing recyclable view that can be modified instead of creating a new view  All the basic ListAdapter methods are implemented in a class BaseAdapter  You will need to subtype this and implement the above methods

Application data  Many times application data comes in the form of lists of objects rather than lists of simple Strings  E.g. contacts are composed  Name  Phone Number   etc  This is the type of data that is best served by custom adapter classes since you will want to present all these somehow to the user

Creating your own Adapter  The most common customization to an adapter is the row’s layout  Given the many methods present in the ListAdapter interface, it is usually better to subclass BaseAdapter and fill the missing methods as stated earlier

getView() public View getView(int position, View convertView, ViewGroup parent) – returns a view object used to render the data  position – represents the position in your dataset  convertView - represents an existing recyclable view that can be modified instead of creating a new view  parent – represents the parent (usually the ListView object) that holds this view

Custom views  Views used for layout rows can be easily created using the Graphical Editor  Created the same way as with an Activity layout  These are the parsed using a LayoutInflater instance inside getView() and populated with the proper data

Example  NOTE: getLayoutInflater() is in the Activity class  i.e. you need access to the Activity to use it either as an inner class or pass the Activity to the Adapter public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.row, null); // extract the views to be populated TextView name = (TextView) view.findViewById(R.id.name); TextView phone = (TextView) view.findViewById(R.id.phone); TextView = (TextView) view.findViewById(R.id. ); // extract the object that will fill these MyContact contact = internalList.get(position); name.setText(contact.getName()); phone.setText(contact.getPhone()); .setText(contact.get ()); // return the view return view; }

Output vs XML <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">