string versus array Klasse Type met speciale syntax Indexer -notatie

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Chapter 17 Templates. Generic Algorithms Algorithms in which the actions or steps are defined, but the data types of the items being manipulated are not.
Manifest File, Intents, and Multiple Activities. Manifest File.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
Array nDeclaratie nCreatie nOpvragen nWijzigen nLengte String [ ] a; a = new String[10]; ……a[5]…… a[5] = ……; …a.length… …is eigenlijk overbodig! ArrayList.
@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.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
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.
ILM Proprietary and Confidential -
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Linking Activities using Intents How to navigate between Android Activities 1Linking Activities using Intents.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
Activity Android Club Agenda Hello Android application Application components Activity StartActivity.
Mobile Programming Midterm Review
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Creating multiple views Introduction to intents Passing data to.
Intents 1 CS440. Intents  Message passing mechanism  Most common uses:  starting an Activity (open an , contact, etc.)  starting an Activity.
(2.2) Hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en methode using Android.OS; using Android.App; using Android.Widget;
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Lecture 2: Android Concepts
Module 13: Properties and Indexers. Overview Using Properties Using Indexers.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Technische Universität München Services, IPC and RPC Gökhan Yilmaz, Benedikt Brück.
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
Intro to C# for Java people
Lecture 2: Android Concepts
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
各種清單資料來源設定法.
Gameprogrammeren: Klassen en objecten in Painter
several communicating screens
Linking Activities using Intents
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
ListView: Part 2.
CS499 – Mobile Application Development
Voorbeeld-programma's
Game Extras Pepper.
Communication between Activities
CS499 – Mobile Application Development
(H9.1) CirkelKlikker ARRAY int x, y; [ ] int n=0;
ITEC535 – Mobile Programming
Android Introduction Camera.
Data Structures Array - Code.
Android Programming Lecture 6
Pass by Reference, const, readonly, struct
Simple Classes in C# CSCI 293 September 12, 2005.
Android Lists and Fragments
Many thanks to Jun Bum Lim for his help with this tutorial.
160 Exam 2 Prep.
Object-Oriented Programming
Multidimensional Arrays
Data Structures Array - Code.
Android Developer Fundamentals V2
CMPE419 Mobile Application Development
Activities and Intents
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Recursion Problems.
Review of Classes and Arrays
CIS 199 Final Review.
Objects First with Java
ListView ? BaseAdapter ?.
ארועים ומאזינים android.
Character Arrays char string1[] = “first”;
Lecture 2: Android Concepts
Arrays Wellesley College CS230 Lecture 02 Thursday, February 1
Objects First with Java
Review of Classes and Arrays
Lasalle-App Tecnología Móvil.
Chengyu Sun California State University, Los Angeles
Presentation transcript:

string versus array Klasse Type met speciale syntax Indexer -notatie string s = new string(); char[] a = new char[10]; Indexer -notatie Speciale index-notatie c = s[2]; s[3] = c; c = a[2]; a[3] = c; Speciale quote-notatie s = "hallo"; Property s.Length Property a.Length Methoden s.IndexOf(t); s.Substring(3,2);

Array / List array: oject dat een rij waarden bevat, met speciale notaties List: array “ingepakt” in een klasse, met extra methodes Declaratie Creatie Opvragen Wijzigen Lengte String [ ] a; List<String> a; List a; a = new String[10]; a = new List<String>(); a = new List(); ……a[5]…… …a.Get(5)… ……a[5]…… a[5] = ……; a[5] = ……; a.Set(5,…); …a.Length… …a.Count… Invoegen Achtervoegen a.Insert(5,…); a.Add(…);

ListView public class KleurenApp : Activity { ListView kleurLijst; ArrayAdapter<string> kleurAdp; string[] kleuren = {"rood", "wit", "blauw"}; protected override void OnCreate(Bundle b) { base.OnCreate(b); kleurLijst = new ListView(this); kleurAdp = new ArrayAdapter<string> (this, SimpleListItemChecked, kleuren); kleurLijst.Adapter = kleurAdp; kleurLijst.ChoiceMode = Multiple; kleurLijst.ItemClick += iklik; SetContentView(kleurLijst); } public void iklik(object o, ItemClickEventArgs e) { string s = kleuren[e.Position]; Toast.MakeText(...s...) . Show( ); } }

ListView

ListView public class KleurenApp : Activity { ListView kleurLijst; ArrayAdapter<string> kleurAdp; string[] kleuren = {"rood", "wit", "blauw"}; public void vvklik(object o, EventArgs e) { string bericht = "mijn kleuren: "; var ps = kleurLijst.CheckItemPositions ; for (int t=0; t<ps.Count; t++) if ( ps.ValueAt(t) ) bericht += kleuren[ ps.KeyAt(t) ] ; Intent i = new Intent(Intent.ActionSend); i.SetType("text/plain"); i.PutExtra(Intent.ExtraText, bericht); StartActivity( i ); } }

ListView public class KleurenApp : Activity { ListView kleurLijst; ArrayAdapter<string> kleurAdp; string[] kleuren = {"rood", "wit", "blauw"}; protected override void OnCreate(Bundle b) { base.OnCreate(b); kleurLijst = new ListView(this); kleurAdp = new ArrayAdapter<string> (this, SimpleListItemChecked, kleuren); kleurLijst.Adapter = kleurAdp; kleurLijst.ChoiceMode = Multiple; kleurLijst.ItemClick += iklik; SetContentView(kleurLijst); } }

ListView public class KleurenApp : Activity { ListView kleurLijst; KleurenAdapter kleurAdp; ArrayAdapter<string> kleurAdp; string[] kleuren = {"rood", "wit", "blauw"}; KleurItem[] kleuren = { new KleurItem("Red", Color.Red), new Kle List<KleurItem> kleurItems = new List<KleurItem(kleuren); protected override void OnCreate(Bundle b) { base.OnCreate(b); kleurLijst = new ListView(this); kleurAdp = new KleurenAdapter (this, kleurItems); kleurAdp = new ArrayAdapter<string> (this, SimpleListItemChecked, kleuren); kleurLijst.Adapter = kleurAdp; kleurLijst.ChoiceMode = Multiple; kleurLijst.ItemClick += iklik; SetContentView(kleurLijst); } }

KleurItem public class KleurItem { public string Naam; public Color Kleur; public KleurItem(string n, Color k) { Naam = n; Kleur = k; } }

Adapter public class KleurenAdapter : BaseAdapter<KleurItem> { Activity activity; List<KleurItem> items; public KleurenAdapter (Activity a, List<KleurItem> ki) { this.activity = a; this.items = ki; } public override View GetView( int pos ) { , View oud TextView view ; = (TextView) oud; if (view==null) view = new TextView(activity); view.Text = items[pos].Naam; view.SetBackgroundColor(items[pos].Kleur); view.SetHeight(100); return view; } }

ListView public class KleurenApp : Activity { public void klik(object o, EventArgs e) { Intent i = new Intent(this, typeof(KleurEdit)); StartActivityForResult( i, 9999 ); } public void iklik(object o, ItemClickEventArgs e) { Intent i = new Intent(this, typeof(KleurEdit)); int pos = e.Position; KleurItem item = kleurItems[pos]; i.PutExtra("naam", item.Naam ); i.PutExtra("kleur", item.Kleur.ToArgb() ); StartActivityForResult( i, pos ); } override void OnActivityResult(int pos, ... ) { ... } }

KleurEdit public class KleurEdit : Activity { string naam; Color kleur; static int nummer = 1; EditText e; protected override void OnCreate(Bundle b) { base.OnCreate(b); zoals in H.3, plus naam = this.Intent.GetStringExtra("naam"); kleur = new Color( this.Intent.GetIntExtra("kleur",0) ; ) if (naam==null) naam = $"nieuw {nummer++}"; e = new EditText(this); e.Text = naam; } private void ok (object o, EventArgs e) { Intent i = new Intent( ); i.PutExtra("naam", e.Text ); i.PutExtra("kleur", kleur.ToArgb() ); SetResult(Result.Ok, i); Finish(); } }

ListView public class KleurenApp : Activity { public void klik(object o, EventArgs e) { ... } public void iklik(object o, ItemClickEventArgs e) { ... } override void OnActivityResult (int pos, Result res , Intent data ) { if (res==Result.Ok) { naam = data.GetStringExtra("naam"); ... KleurItem k = new KleurItem(naam,kleur); if (pos==9999) kleurItems.Add( k ); else kleurItems[pos] = k; } else if (pos < 9999) kleurItems.RemoveAt( pos ); } }