Download presentation
Presentation is loading. Please wait.
Published byBertha van Loon Modified over 6 years ago
1
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);
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(…);
3
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( ); } }
4
ListView
5
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 ); } }
6
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); } }
7
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); } }
8
KleurItem public class KleurItem { public string Naam;
public Color Kleur; public KleurItem(string n, Color k) { Naam = n; Kleur = k; } }
9
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; } }
10
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, ... ) { ... } }
11
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(); } }
12
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 ); } }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.