@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.

Slides:



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

Programming with Android: Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Copyright© Jeffrey Jongko, Ateneo de Manila University Dialogs, Custom Dialogs, Toasts.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
@2010 Mihail L. Sichitiu1 Android Introduction Hello Views Part 2.
@2011 Mihail L. Sichitiu1 Android Introduction Communication between Activities.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
1 Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources, Listener 10/9/2012 Y. Richard Yang.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
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.
Chapter 9: Customize! Navigating with Tabs on a Tablet App.
Android Tutorial Team 3 Jerry Yu Mayank Mandava Mu Du Will Wangles.
Wireless Mobility with Android 1 Presented by: Ung Yean MS. Computer Science American University, Washington DC, USA.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Chapter 2: Simplify! The Android User Interface
Android Activities 1. What are Android Activities? Activities are like windows in an Android application An application can have any number of activities.
Understanding Hello Android 1 CS300. Activity  Similar to a form  Base class for the visual, interactive components of your application  Android API.
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
CHAP 10. 고급 위젯. © 2012 생능출판사 All rights reserved 어댑터 뷰 어댑터 뷰 (AdapterView) 는 배열이나 파일, 데이터 베이스에 저장된 데이터를 화면에 표시할 때 유용한 뷰.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Mobile Programming Lecture 5 Composite Views, Activities, Intents and Filters.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
User Interface Android Club Agenda Button OnClickListener OnLongClickListener ToggleButton Checkbox RatingBar AutoCompleteTextView.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Mobile Programming Midterm Review
New Activity On Button Click via Intent. App->res->Layout->Blank Activity A new xml file is created and a new class is added to java folder. In manifest.xml.
Mobile Programming Lecture 7 Dialogs, Menus, and SharedPreferences.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Android Application Lifecycle and Menus
Activities and Intents Richard S. Stansbury 2015.
Frank Xu Gannon University. A dialog is always created and displayed as a part of an Activity. You should normally create dialogs from within.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Chapter 2: Simplify! The Android User Interface
Android Introduction Hello World
CS499 – Mobile Application Development
Android N Amanquah.
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
GUI Programming Fundamentals
Further android gui programming
Android – Event Handling
ListView: Part 2.
Android Introduction Hello World.
Communication between Activities
Android Widgets 1 7 August 2018
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Android Introduction Hello Views Part 1.
ITEC535 – Mobile Programming
Picasso Revisted.
Android Programming Lecture 6
MultiUni Trần Vũ Tất Bình
ANDROID LISTS.
Android Lists and Fragments
Many thanks to Jun Bum Lim for his help with this tutorial.
CMPE419 Mobile Application Development
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Android Topics Custom ArrayAdapters Creating an Event Listener
Activities, Fragments, and Intents
CA16R405 - Mobile Application Development (Theory)
Presentation transcript:

@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1

@2011 Mihail L. Sichitiu2 Goal  Familiarize with the main types of GUI components  Concepts: Layouts Widgets Menus

@2011 Mihail L. Sichitiu3 Linear Layout <TextView android:text="red" android:gravity="center_horizontal" […………………….] […………………………………..]

@2011 Mihail L. Sichitiu4 One Layout, two views XML File vs Layout Preview

@2011 Mihail L. Sichitiu5 Relative Layout 

@2011 Mihail L. Sichitiu6 Table Layout [………………………]

@2011 Mihail L. Sichitiu7 TabLayout  One activity per tab  Create new Project HelloTabs

@2011 Mihail L. Sichitiu8 Create three new activities  Right click on HelloTabs Package Name -> New -> Class  Right click on the new class, Source -> Override/Implement Methods -> Check OnCreate();

@2011 Mihail L. Sichitiu9 Fill in the OnCreate() method public class ArtistsActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textview = new TextView(this); textview.setText("This is the Artists tab"); setContentView(textview); } } Quick and dirty “by hand” like in HelloWorld Copy and Paste ArtistsActivity into two more activities:  AlbumsActivity and  SongsActivity

@2011 Mihail L. Sichitiu10 Copy the icons  Right click -> Save As,  Make./res/drawable  move the icons into./res/drawable

@2011 Mihail L. Sichitiu11 Create./res/drawable/ic_tab_artists.xml StateListDrawable object that displays different images for different states of a View

@2011 Mihail L. Sichitiu12 Make copies or the xml files for the other two tabs:  Copy the xml file: ic_tab_artists.xml ->  ic_tab_albums.xlm ->  ic_tab_songs.xml

@2011 Mihail L. Sichitiu13 Main Layout 

@2011 Mihail L. Sichitiu14 OnCreate() for HelloTabs (main activity) public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs [………………………] tabHost.setCurrentTab(2); } Main Activity is a TabActivity – has a TabHost Builder mapping the resources to the tab Select Tab 2

@2011 Mihail L. Sichitiu15 Run it!

@2011 Mihail L. Sichitiu16 List View  List of scrollable items  Application will inherit from ListActivity rather than Activity  Create./res/layout/list_item.xml Layout for each item

@2011 Mihail L. Sichitiu17 public class HelloListView extends ListActivity { /** Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter (this, R.layout.list_item, COUNTRIES)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.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(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } }); } Override the OnCreate method Setup the list for this application, with this layout and this content Enables filtering by keyboard Small Toast showing the text in the clicked item for a short time

@2011 Mihail L. Sichitiu18 Run it!

@2011 Mihail L. Sichitiu19 Date Picker  Will display a dialogbox allowing to change the date

@2011 Mihail L. Sichitiu20 Layout

@2011 Mihail L. Sichitiu21 OnCreate( ) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // capture our View elements mDateDisplay = (TextView) findViewById(R.id.dateDisplay); mPickDate = (Button) findViewById(R.id.pickDate); // add a click listener to the button mPickDate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(DATE_DIALOG_ID); } }); // get the current date final Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); // display the current date (this method is below) updateDisplay(); }

@2011 Mihail L. Sichitiu22 updateDisplay( ) // updates the date in the TextView private void updateDisplay() { mDateDisplay.setText( new StringBuilder() // Month is 0 based so add 1.append(mMonth + 1).append("-").append(mDay).append("-").append(mYear).append(" ")); }

@2011 Mihail L. Sichitiu23 DatePickerDialog.OnDateSetListener( ) // the callback received when the user "sets" the date in the dialog private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; updateDisplay(); } };

@2011 Mihail L. Sichitiu24 onCreateDialog( protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); } return null; }

@2011 Mihail L. Sichitiu25 Run it!