2012年5月29日火曜日

開閉ListView

ListViewのオプションであんだろーと思いきや別ビューだった、残念

ということで使うのはExpandableListViewとやら。
親→子の概念を持ったリスト。
adapterセットに使う引数は驚きの9個!9個ですよ奥さん!

(ttp://dev.classmethod.jp/smartphone/basic-android-component-03-expandablelistview/)
を全面的に参考。

親と子の定義。



    ArrayList<HashMap<String, String>> parent
         = new ArrayList<HashMap<String,String>>();

    ArrayList<ArrayList<HashMap<String, String>>> child
         = new ArrayList<ArrayList<HashMap<String,String>>>();

親グループ定義。ここでは一個だけ。


    HashMap<String, String> group1 = new HashMap<String, String>();
    groupA.put("group", "成人病");


ぶち込み。

parent.add(group1)


子定義。


  ArrayList<HashMap<String, String>> childList = new ArrayList<HashMap<String,String>>();
    HashMap<String, String> child1 = new HashMap<String, String>();
    child1.put("group", "成人病");
    child1.put("name", "肝硬変");
    HashMap<String, String> child2 = new HashMap<String, String>();
    child2.put("group", "成人病");
    child2.put("name", "糖尿");


子と親の結びつけはキーで結ぶ。ここで言うgroup。
ぶち込み。

childList.add(child1)
childList.add(child2)

listをぶち込み。

childData.add(childList)


adapter。


       SimpleExpandableListAdapter Exadapter1 = new SimpleExpandableListAdapter(
               getApplicationContext(),
               groupData,
               android.R.layout.simple_expandable_list_item_1,
               new String[] {"group"},
               new int[] { android.R.id.text1 },
               childData,
               R.layout.onedata,
               new String[] {"name"},
               new int[] { R.id.rowtext1});

親と子で使うレイアウト変えてるけどまぁこんな感じ。
コンテキストのあとはデータ、レイアウト、キー値、レイアウトのリソースIDの順。
子要素の数だけhashmapをnewする必要があるのでDB絡める実装はちょい考え中。
うーん。



2012年5月23日水曜日

csvからDB作成

ポイントは2つ。

・csvファイル保管場所

project/res/rawに保管。
読まれたくない場合はassetsに突っ込むがその場合普通にパス指定しただけでは読めないので注意。


・リソースID指定

読む際はR内に定義される先頭ポインタ?じゃないかもしれないけどID値を取得。
resouceid = r.raw.resource;
InputStream is = resource.OpenRawResource(ResourceID);

こんなん。


DBに詰めるのはInsertHelperを使った。

参照:ttp://d.hatena.ne.jp/ipreachable/20110129/1296326520

一個困ってるのが、csv内にエスケープシーケンス(\n)を書くと(\N)になってしまう点。
うーむ。

2012年5月17日木曜日

ListViewの罫線を変える

divider="色コード"
dividerHeight="サイズ"

で変更可。
サイズはピクセル指定可。

2012年5月8日火曜日

軟弱なmax野郎どもが!!

imageviewにmax~が全く効かない。

android:maxWidth="fu*k"とか書いてたんですが、
どうやらandroid:adjustviewboundsとやらを設定してやれば行ける模様。
どれどれ・・・


あらーほんとだ行けた。
いやはや。

デフォルトでfalseになってるのがよくわからん。なんでだろう。
layout_weightとか使ったりしてたんですが、微調整効かないんでこっち使用。
静的な設定をとことん嫌がるってことなんでしょうか。

2012年5月6日日曜日

背景の透過

背景画像を指定

android:background="@drawable/oops.jpg"

で、「manifest」に移ってandroid:theme="@android:style/Theme.Translucent"を追加。