Professional Documents
Culture Documents
Tranning Android
Tranning Android
1. Cc Widget s dng - ImageView, AutoCompleteTextView 2. Intent, Thread, Service 3. Phn tch, x l file XML 4. Cc bc ly thng tin thi tit t Yahoo API
ImageView
- hin th mt nh bt k. ImageView class c th load nh t nhiu ngun khc nhau: + android:src: thit lp 1 drawable nh l thnh phn ca ImageView
ImageView
- Lng nghe s kin click ImageView: Search: ImageView android
AutoCompleleTextView
L editable text, t ng hin cc gi hon chnh khi ngi dng nhp. Danh sch cc gi s c hin th trong 1 menu th xung. Danh sch cc gi c ly t data adapter v xut hin ch khi s lng k t xc nh c nhp: android:completionThreshold. addTextChangedListener(this): thm mt TextWatcher lit k cc phng thc c gi bt k khi no k t ca TextView thay i.
AutoCompleleTextView
- setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strtt)): thay i danh sch ca d liu s dng cho t ng hon thnh. - Mt Adapter hot ng nh mt cu ni gia mt View v d liu cho ci View y. - ArrayAdapter cha mt mng cc i tng bt k - Search: Adapter android
Intent
Mt ng dng Android c th bao gm nhiu Activity. Cc Activity lun hp tc trao i d liu v hot ng vi nhau. Vic di chuyn t Activity ny ti mt Activity khc c thit lp bi vic gi Activity hin ti thc thi mt Intent. Cc Activity tng tc vi nhau trong mt ch n danh
- Reference: http://duythanhcse.wordpress.com/2013/04/19/baitap-24-thuc-hanh-ve-intent-trong-android/
- Gi Intent chy 1 Activity: startActivity (intent) - Intent intent = new Intent(MainActivity.this, Weather.class): to mt Intent mi vi MainActivity.this (l Context hin ti) v Weather.class (Activity cn m).
Thread
Thread (Tin trnh) c s dng lm mt vic g y mt cch ngm nh (chy nn) - Thread myThread = new Thread(new Runnable() {}): To 1 Thread mi. - myThread.start (): chy Thread. - runOnUiThread(new Runnable() {}): Trao i d liu gia lung Background v lung chnh, chy trn lung chnh. - Reference: http://android.vn/threads/gioithieu-da-luong-multi-thread-tronglap-trinh-ung-dung-android-phan1.24616/
Service
Service l mt thnh phn ng dng, chy trong background, khng tng tc vi ngi dng. Mi Service class phi c khai bo <service> tng ng trong AndroidManifest.xml ca package. Reference: http://mobilepro.vn/mobilepro/index.php/thu-vin-nh/thu-vin-bai-ging/bai-ginglp-trinh-android/26-hung-dn-lp-trinh-co-bn-vi-android-bai-5 Example: ConnectivityManager connMgr; connMgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); - ConnectivityManager: class kim tra trng thi ca kt ni mng. N thng bo cho ng dng khi kt ni mng thay i. - Ly mt i tng ca class ny bng: getSystemService(CONNECTIVITY_SERVICE); - Reference: http://developer.android.com/reference/android/net/ConnectivityManager.html - NetworkInfo: class m t trng thi ca mt giao din mng. S dng getActiveNetworkInfo() ly mt i tng i din cho kt ni mng hin ti - Reference: http://developer.android.com/reference/android/net/NetworkInfo.html