2016年5月26日 星期四

Error: ArrayAdapter requires the resource ID to be a TextView

Reference:

http://stackoverflow.com/questions/9280965/arrayadapter-requires-the-resource-id-to-be-a-textview-xml-problems

Illustration:

Layout xml裡只能包含一個 TextView,不能將 TextView包在其他的 layout裡,例如:LinearLayou

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ......
/>

2016年5月6日 星期五

String Resources: Formatting and Styling

References:

http://developer.android.com/intl/zh-tw/guide/topics/resources/string-resource.html#FormattingAndStyling


Example:

<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);

TextView 省略文字的用法

Reference:

http://blog.csdn.net/sonicliji/article/details/8523746

illustration:

1.android:ellipsize=”start”—–省略號顯示在開頭
Ex: ......start
2.android:ellipsize=”end”——省略號顯示在結尾
Ex: end.......
3.android:ellipsize=”middle”—-省略號顯示在中間
4.android:ellipsize=”marquee”–以跑馬燈的方式顯示(動畫橫向移動)

2016年4月27日 星期三

Android Studio build error: illegal character: '\ufeff'

References:

http://nobodycare.me/2014/11/07/android-studiode-common-questions/
http://www.codegur.net/36027875/character-set-issue-utf-8
http://lifelongprogrammer.blogspot.tw/2014/05/powershell-and-java-stumble-by-utf8-bom.html

Scenario:

Import android project from Eclipse to Android Studio.

Error message:

illegal character: '\ufeff'


Root cause:

The invisible prefix is \ufeff. U+FEFF is byte order mark (BOM).
But java uses utf8 without bom to read file.

Solution:

Opened the document in notepad and changed the encoding to UTF-8 to save it.

2016年4月19日 星期二

Install Android device driver

References:
http://j796160836.pixnet.net/blog/post/29610725

Step:
1. 到 Android SDK Manager裡安裝 Google USB Driver
2. 進入裝置管理員
3. 找到 Android device,右鍵選擇“更新驅動程式”
4. 瀏覽電腦上的驅動程式軟體
5. 讓我從電腦上的裝置驅動程式清單中挑選
6. 從磁碟安裝
7. 選擇  <你裝的android SDK的路徑>\extras\google\usb_driver\android_winusb
例如:
C:\Users\HueiJheYu\AppData\Local\Android\sdk\extras\google\usb_driver\android_winusb
8. Android ADB Interface

2016年4月7日 星期四

Android UriMatcher.addURI中的 /# 和 /* 解释

Reference:
http://bbs.isgphone.com/archiver/tid-6755.html

說明:
* may be used as a wild card for any text, and # may be used as a wild card for numbers
*: 任何字元
#: 任何數字

The difference between getMeasuredHeight() and getHeight()

Reference:
http://blog.csdn.net/xujainxing/article/details/8985063

說明:
getMeasuredHeight() 是 View實際的大小
getHeight() 是 View 在 Screen內的大小
如果 View超出 Screen的邊界時,getMeasuredHeight() = getHeight() + View超出 Screen的大小