You are on page 1of 11

Ni dung

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

+ android:layout_gravity: cn l cc widget trn giao din. + android:gravity: cn l ni dung bn trong ca widget

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

XML Dng DOM


DOM (Document Object Model ): Cache all c ch ca n l c ton b ni dung tp tin XML vo b nh (do nu XML ln th lm chm chng trnh v c th phung ph b nh v khng phi lc no ta cng mun c ht ni dung XML). DOM cho php ly: NodeLists, .getElementsByTagName() , .item(i), .getName() , .getValue() , .getFirstChild() , .getAttributes(), Example:

XML Dng DOM


1. Bc 1: To i tng DocumentBuilder (builder ) DocumentBuilderFactory fac=DocumentBuilderFactory.newInstance(); DocumentBuilder builder=fac.newDocumentBuilder(); 2. Bc 2: To FileInputStream t tp tin XML ngun ( XML ngun trong SD Card) String sdcard=Environment.getExternalStorageDirectory().getAbsolutePath(); String xmlfile=sdcard+"/employee.xml"; FileInputStream fIn=new FileInputStream(xmlfile); 3. Bc 3: Dng phng thc parse ca i tng builder bc 2 to Document Document doc=builder.parse(fIn); 4. Bc 4: Ta da vo i tc doc c to ra bc 4 duyt tng node trong XML: Reference: http://duythanhcse.wordpress.com/2013/05/31/bai-tap-29-xml-parser-trongandroid/ http://developer.android.com/training/basics/network-ops/xml.html http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/

Thng tin thi tit t Yahoo API


Reference: http://android.vn/threads/huong-dan-lam-mot-ung-dung-xem-thoi-thiet-dongian-tu-du-lieu-cua-yahoo.25668/ http://developer.yahoo.com/weather/ Yahoo cung cp d liu thi tit thng qua http://weather.yahoo.com/ D liu bao gm a phng, thi tit, sc gi, thin vn hc ... di dng mt web xml To mt kt ni ti d liu xml ny: mi vng c mt ID ring: http://weather.yahooapis.com/forecastrss?w=1252438: s dng HTTP Ly d liu a phng v hin th QueryYahooWeather(): truy vn Yahoo weather API convertStringToDocument(String src): chuyn sang Document phn tch file nhn c t Yahoo weather API parseWeather(Document srcDoc): phn tch Document ly thng tin thi tit

You might also like