Practical 1.ListView example

Similar documents
Android Apps Development for Mobile and Tablet Device (Level I) Lesson 4. Workshop

1. Simple List. 1.1 Simple List using simple_list_item_1

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

Creating a Custom ListView

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Developing Android Applications

ListView Containers. Resources. Creating a ListView

ActionBar. import android.support.v7.app.actionbaractivity; public class MyAppBarActivity extends ActionBarActivity { }

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

Fragment Example Create the following files and test the application on emulator or device.

Accelerating Information Technology Innovation

Android Layout Types

android:layout_margintop="5dp" > <EditText android:layout_width="210dp"

LAMPIRAN PROGRAM. public class Listdata_adiktif extends ArrayAdapter<ModelData_adiktif> {

Adapter.

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

Arrays of Buttons. Inside Android

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar


Intents. Your first app assignment

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Lecture 14. Android Application Development

B6: Time to coding. Đi tới src\at.exam tạo một class mới là CustomViewGroup với nội dung sau: Mã: package at.exam;

Introduction. Who Should Read This Book. Key Topics That This Book Covers

else if(rb2.ischecked()) {

Simple Currency Converter

Mobile Programming Lecture 3. Resources, Selection, Activities, Intents

Database Development In Android Applications

ListView (link) An ordered collection of selectable choices. key attributes in XML:

Basic GUI elements - exercises

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Android HelloWorld - Example. Tushar B. Kute,

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Mobile Computing Practice # 2a Android Applications - Interface

Android Workshop: Model View Controller ( MVC):

INTRODUCTION COS MOBILE DEVELOPMENT WHAT IS ANDROID CORE OS. 6-Android Basics.key - February 21, Linux-based.

Android CardView Tutorial

Create Parent Activity and pass its information to Child Activity using Intents.

Graphical User Interfaces

Meniu. Create a project:

Android List-Based Selection Widgets

5Displaying Pictures and Menus with Views

List-Based Widgets: Lists, Grids, and Scroll Views

Tip Calculator. xmlns:tools=" android:layout_width="match_parent"

ANDROID USER INTERFACE

Introductory Mobile App Development

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

App Development for Smart Devices. Lec #7: Audio, Video & Telephony Try It Out

Manifest.xml. Activity.java

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

When programming in groups of people, it s essential to version the code. One of the most popular versioning tools is git. Some benefits of git are:

Starting Another Activity Preferences

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University. Overview (Review)

Adapters. Marco Ronchetti Università degli Studi di Trento

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Android Beginners Workshop

Chapter 7: Reveal! Displaying Pictures in a Gallery

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Chapter 8 Positioning with Layouts

Charlie Collins Michael Galpin Matthias Käppler IN PRACTICE. Includes 91 Techniques SAMPLE CHAPTER MANNING

Computer Science E-76 Building Mobile Applications

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

MyDatabaseHelper. public static final String TABLE_NAME = "tbl_bio";

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University

Action Bar. (c) 2010 Haim Michael. All Rights Reserv ed.

OPTIMIZING ANDROID UI PRO TIPS FOR CREATING SMOOTH AND RESPONSIVE APPS

The Android Tablet Developer s Cookbook

Java & Android. Java Fundamentals. Madis Pink 2016 Tartu

Preferences. Marco Ronchetti Università degli Studi di Trento

Android Programs Day 5

Q.1 Explain the dialog and also explain the Demonstrate working dialog in android.

Embedded Systems Programming - PA8001

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Lesson 5. List-Based Selectors. List-Based Selector: Lists, Grids, and Scroll Views... 3

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

Action Bar. Action bar: Top navigation bar at each screen The action bar is split into four different functional areas that apply to most apps.

The World of List View. Romain Guy and Adam Powell May 19, 2010

COMP4521 EMBEDDED SYSTEMS SOFTWARE

More Effective Layouts

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Android Services. Victor Matos Cleveland State University. Services

App Development for Smart Devices. Lec #18: Advanced Topics

Topics of Discussion

<uses-permission android:name="android.permission.internet"/>

TextView. A label is called a TextView. TextViews are typically used to display a caption TextViews are not editable, therefore they take no input

GUI Widget. Lecture6

API Guide for Gesture Recognition Engine. Version 2.0

Adaptation of materials: dr Tomasz Xięski. Based on presentations made available by Victor Matos, Cleveland State University.

Mobila applikationer och trådlösa nät, HI1033, HT2012

Upon completion of the second part of the lab the students will have:

Advanced Android Development

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

Mobila applikationer och trådlösa nät, HI1033, HT2013

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Transcription:

Practical 1.ListView example In this example, we show you how to display a list of fruit name via ListView. Android Layout file File : res/layout/list_fruit.xml <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textsize="20sp" > </TextView> ListView ListFruitActivity.java package com.mkyong.android; import android.app.listactivity; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.arrayadapter; import android.widget.listview; import android.widget.textview; import android.widget.toast; import android.widget.adapterview.onitemclicklistener;

public class ListFruitActivity extends ListActivity { static final String[] FRUITS = new String[] { "Apple", "Avocado", "Banana", @Override "Blueberry", "Coconut", "Durian", "Guava", "Kiwifruit", "Jackfruit", "Mango", "Olive", "Pear", "Sugar-apple" ; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // setcontentview(r.layout.list_fruit); setlistadapter(new ArrayAdapter<String>(this, R.layout.list_fruit,FRUITS)); ListView listview = getlistview(); listview.settextfilterenabled(true); listview.setonitemclicklistener(new OnItemClickListener() { public void onitemclick(adapterview<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), Toast.LENGTH_SHORT).show(); ((TextView) view).gettext(), ); Output

Practical 2. Custom ArrayAdapter example In this example, we show you how to create 4 items in the ListView, and use a custom ArrayAdapter to display different images base on the item name in the list. Get 4 images for demonstration and paste to res/drawable/ folder. Based on your image file names, you have to change the resource id names R.drawables.<your image file name> in the MobileArrayAdapter.java file. Android Layout file File : res/layout/list_mobile.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" > <ImageView android:id="@+id/logo" android:layout_width="50px" android:layout_height="50px"

android:layout_marginleft="5px" android:layout_marginright="20px" android:layout_margintop="5px" android:src="@drawable/windowsmobile_logo" > </ImageView> <TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@+id/label" android:textsize="30px" > </TextView> </LinearLayout> Custom ArrayAdapter Create a class extends ArrayAdapter and customize the item display in the getview() method. MobileArrayAdapter.java package com.mkyong.android.adaptor; import com.mkyong.android.r; import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;

import android.widget.arrayadapter; import android.widget.imageview; import android.widget.textview; public class MobileArrayAdapter extends ArrayAdapter<String> { private final Context context; private final String[] values; public MobileArrayAdapter(Context context, String[] values) { super(context, R.layout.list_mobile, values); this.context = context; this.values = values; @Override public View getview(int position, View convertview, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getsystemservice(context.layout_inflater_service); false); View rowview = inflater.inflate(r.layout.list_mobile, parent, TextView textview = (TextView) rowview.findviewbyid(r.id.label); ImageView imageview = (ImageView) rowview.findviewbyid(r.id.logo); textview.settext(values[position]); // Change icon based on image file name String s = values[position]; System.out.println(s); if (s.equals("windowsmobile")) { imageview.setimageresource(r.drawable.windowsmobile_logo);

else if (s.equals("ios")) { imageview.setimageresource(r.drawable.ios_logo); else if (s.equals("blackberry")) { imageview.setimageresource(r.drawable.blackberry_logo); else { imageview.setimageresource(r.drawable.android_logo); return rowview; Change the file names based on your image file names ListView ListView, but use above custom adapter to display the list. package com.mkyong.android; import com.mkyong.android.adaptor.mobilearrayadapter; import android.app.listactivity; import android.os.bundle; import android.widget.listview; import android.widget.toast; import android.view.view; public class ListMobileActivity extends ListActivity { static final String[] MOBILE_OS = new String[] { "Android", "ios", "WindowsMobile", "Blackberry"; @Override

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setlistadapter(new MobileArrayAdapter(this, MOBILE_OS)); @Override protected void onlistitemclick(listview l, View v, int position, long id) { //get selected items String selectedvalue = (String) getlistadapter().getitem(position); Toast.makeText(this, selectedvalue, Toast.LENGTH_SHORT).show(); Output Try it your self:

Create an Android project to display a set of countries with the flag and its currency as indicated in the image below. Hint : create a layout file with an mageview and two textviews as shown below: Image View Text View Text View