跳到主要內容

發表文章

目前顯示的是 2012的文章

[Android]Send Message To android.os.Handler的快速寫法

快速寫法: mHandler.sendMessage(mHandler. obtainMessage (MSG_ADD_TO_PLAYLIST, intent)); 其內部其實就是: public final Message obtainMessage(int what, Object obj)     {         return Message.obtain(this, what, obj);     } public static Message obtain(Handler h, int what, Object obj) {         Message m = obtain();         m.target = h;         m.what = what;         m.obj = obj;         return m;     }

Programming Language 大比較

Programming Language 大比較 Constructor     使用一 Class     class Vector     {         public Vector()         {             //Do Something         }         public Vector(int i)         {              //Do Something         }     } In C++   Vector u();       Vector v(10); In Java,C#    Vector u = new Vector();    Vector v = new Vector(10);

[Android]Android中的Intent.FLAG_ACTIVITY_NEW_TASK

Android中的Intent.FLAG_ACTIVITY_NEW_TASK i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 有此行程式可將不同的activity看成好像是同一個應用程式 當你從 主activity 跳至 另一個activity (此activity早己存在於系統之中) 當你按下"back"後它會跳回主activity 如果沒加入此程式當按下"back"後它則會離開主activity

[Android]Google Map View的一堆陷阱!!!

以下是Google Map View的一堆陷阱!!! 請小心服用: 基本常識區: 1. 需使用MapActivity 2. <uses-library android:name="com.google.android.maps"/> 3. <uses-permission android:name="android.permission.INTERNET"/> 4. API Key, Sign APK 陷阱區: 1.在加入ItemizedOverlay後請使用 invalidate 重繪         mMapView.getOverlays().add(draggableItemizedOverlay);         mMapView.invalidate(); 2.ItemizedOverlay其super(drawable)建構子的drawable可以為NULL 3.加入ItemizedOverlay的OverlayItem 其drawable可以是使用預設(即建構子時給的,此時加入的 OverlayItem 可不用.setMarker) 或使用各Item的Marker,在AddItem前.setMarker 務必記住其drawable皆需要在ItemizedOverlay中呼叫 boundCenterBottom(drawable) !! 沒叫會看不見

[Android]取得與綁定Activity的Label,Description

在AndroidManifest中綁定Activity的標籤(Label)與敘述(Description)  <activity        android:name=".activity.ResourceSearchViewActivity"       android:theme="@style/Theme.Sherlock.SearchView"        android:label ="@string/resource_search_view_title"        android:description ="@string/resource_search_view_descr"/> 在Java中解析 PackageManager mPackageManager = context.getPackageManager(); ResolveInfo info = mPackageManager.resolveActivity( YOUR_Intent , 0); title.setText( info.activityInfo.labelRes ); descr.setText( info.activityInfo.descriptionRes );

Android Thread Constructs

Android Thread Constructs Service Thread IntentService AsyncTask When to use ? Task with no UI, but shouldn't be too long. Use threads within service for long tasks. - Long task in general. - For tasks in parallel use Multiple threads (traditional mechanisms) - Long task  usually  with no communication to main thread. (Update) - If communication is required, can use main thread handler or broadcast intents [3] - When callbacks are needed (Intent triggered tasks).  - Long task having to communicate with main thread. - For tasks in parallel use multiple instances OR Executor  [1] Trigger Call to method onStartService() Thread start() method Intent Call to method execute() Triggered From (thread) Any thread Any Thread Main Thread (Intent is received on main thread and then worker thread is spawed) Main Thread Runs On (thread) Main Thread Its own thread Separate worker thread Worker thread. However, Main thread methods may be invoked in betw...

[Android]自定義View的概要與Source Code資源

Android Develpers官網提供的範例: Creating a View Class http://developer.android.com/training/custom-views/create-view.html Sample Code URL: http://developer.android.com/shareables/training/CustomView.zip 自定義一個View的方法: 步驟一 :     開一Java檔extends         (1)最原生的View         (2)ViewGroup         --------Layout類--------         (3)LinearLayout         (4)FrameLayout         --------元件類--------         (5)Button    ... 步驟二 :      在res\values\attrs.xml定義屬性     <resources>     <declare-styleable name="PieChart">      <!--需與Java檔的ClassName相同 -->         <attr name="autoCenterPointerInSlice" format="boolean"/>         <attr name="highlightStrength" format="float"/>        ...

[Android]ArrayAdapter , List of Intent with item name , Get Clicked Item

利用ArrayAdapter的           ArrayAdapter ( Context  context, int resource, int textViewResourceId, T[] objects) Constructor 收Object,再覆寫該Object的ToString方法: class Item extends Intent {     String s;     public Item(Class<?> c, String s) {     super(Test.this, c);     this.s = s; }         @Override     public String toString () {     return s;     }     } 範例: Item[] items = {         new Item(TestPanels.class, "Test Panels"),         new Item(TestSwitcher.class, "Test Switcher"),         new Item(TestSmoothButton.class, "Test SmoothButton"),         new Item(TestInterpolators.class, "Test Interpolators"),         new Item(TestTheme.class, "Test Theme"),         new Item(T...

[Android]由XML設定OnClick事件

<Button android:id="@+id/button1" android:layout_height="wrap_content" android:text="Save" android:layout_width="fill_parent" android:layout_margin="3dp" android:onClick="save"></Button>  public void save(View view) { String nameText = name.getText().toString(); String surnameText = surname.getText().toString(); String ageText = age.getText().toString(); if (nameText != null) PreferenceConnector.writeString(this, PreferenceConnector.NAME, nameText); if (surnameText != null) PreferenceConnector.writeString(this, PreferenceConnector.SURNAME, surnameText); if (ageText != null && !ageText.equals("")) PreferenceConnector.writeInteger(this, PreferenceConnector.AGE, Integer.parseInt(ageText)); }

[Android]由XML設定按鈕觸碰時換圖片效果

set ImageButton's background to the following XML drawable file: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_pressed="false"           android:drawable="@drawable/btn_normal" />         <item android:state_pressed="true"           android:drawable="@drawable/btn_pressed" /> </selector>

[Android]在XML中設定實心顏色、圓角弧邊、顏色、透明、漸層

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >     <item>         <shape>             <!-- 實心顏色   透明為"#00000000" -->             <solid android:color="#FFEEEEEE" />               <!-- 圓角弧邊 -->             <corners                                                                      android:bottomLeftRadius="10dp"                    android:bottomRightRadius="10dp"                    android:topLeftRadius="10dp"     ...