Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Friday, February 21, 2014

Gson (on Android Studio)

Why I met with Gson?

While I was try to store one whole complex object into SharedPerference in Android code, I found that it's default basic data types are not supporting. Also, it's hard to decode them in to json string unless I am writing it's custom encoding function.

Then, I found people are solving this problem using Gson on StackOverflow.

Intro for Gson

"Gson is a Java library that can be used to convert Java Objects into their JSON representation."

Install Gson on Android Studio

Follow the top answer in this StackOverflow thread.

Usage



Thursday, January 23, 2014

Menu Collapses when Using PageViewer (Action Bar Tabs)

寫Android App時,使用viewpager會在actionbar上頭產生tab,而如果使用R.menu內的xml檔案,我們可以在右上角產生action button,但我發現他們都疊在一起了(collapse),根據文件,應該在設定成ifRoom之後在有空間情況下會直接出現在action bar而非下拉選單。

於是我上網找詢問解決方法,得到以下:


在tag設定上,我們應該注意showAsAction前的namespace應該用一個同於第二行xmlns底下的名稱。相同之後問題就解決了!

Reference