2011年12月27日 星期二

[Android] Intent extra value

Intent intent = new Intent();
intent.putExtra("A", "x");
intent.putExtra("A", 1);
// value of key A will be int 1 finally.

// So if i want to get the String from key A it will have error!
String a = intent.getStringExtra("A");

[Android] Call getResource() after onCreate()

Error Message

12-13 14:49:27.316: E/AndroidRuntime(881): Caused by: java.lang.NullPointerException
12-13 14:49:27.316: E/AndroidRuntime(881): at android.content.ContextWrapper.getResources(ContextWrapper.java:81)

Occurred when
call getResources out of onCreate


Solution

Must using getResource() after onCreate()

...but why?

2011年12月17日 星期六

[AndroidLayout] ListView and related adapter

最常用的有幾種Adapter:
  • ArrayAdapter
    • 將一組數組(ex: String[ ]) 連繫到 ListView
  • SimpleAdapter
    • 適用於自訂 ListView items 內容樣式的情況(ex: ArrayList<HashMap<String, Object>>)
  • BaseAdapter
    • 抽象類別,所以有多個方法需要實作。
    • 適用於需要自訂 ListView 外觀等靈活應用的場合。
  • SimpleCursorAdapter
    • 將一組現有的資料庫或聯絡人等ContentProvider的資料查詢的結果連繫到Lis


在android系統中預設就有存在了。其中常用的的這些樣式如下所列:
  • android.R.layout.simple_list_item_1
    • 一行text
  • android.R.layout.simple_list_item_2
    • 一行text較大,一行text較小
    • ArrayAdapter並不支援傳入兩個字串參數值,所以較適用於SimpleAdapter。
  • android.R.layout.simple_list_item_single_choice
    • 單選
  • android.R.layout.simple_list_item_multiple_choice
    • 多選按鈕
  • android.R.layout.simple_list_item_checked
    • 勾選盒


自訂 Adapter 時(extends BaseAdapter) 需實作 getView():
  • getView回傳的是一個View物件,回傳的是每一列的要顯示資料的樣子。
  • position
    • 指的是引入Adapter的資料數組的位置。
  • convertView
    • 指的是轉換過的樣子。
  • parent
    • 指的是每個項目視圖上層包含的容器(Container)。


* Reference
- Eddy@Joomla!藏經閣 - ListView之一:Adapter介紹與使用
- Eddy@Joomla!藏經閣 - ListView之二:改寫ArrayAdapter的getView

2011年12月7日 星期三

[Android] startActivity by external component

Error Message
Uncaught handler: thread main exiting due to uncaught exception
java.lang.SecurityException: Permission Denial: starting Intent { cmp=..../.TestActivity } from ProcessRecord{44710d48 4955../10053} (pid=4955, uid=10053) requires null

Occurred when call A activity from B activity of B application.


Solution

Add this intent-filter in B activity will solve this error.

    



* Reference
- http://hi.baidu.com/spare_h/blog/item/27c25edc800e5ff577c63857.html

[SQL] select...from...where...

select: 決定使用的欄位(column)

from: 資料的來源(所有被列在此的來源都會包含入)

where: 決定取出的資料筆 (row)