2011年4月5日火曜日

ListView選択状態カスタマイズ

ListViewでchecked状態のitemをラジオボタンやチェックボックスでなくセレクタのような形で表示するには。

本当は選択状態のキープは推奨されていない。様々な入力モードを持つデバイスをサポートするため。
http://www.techdoctranslator.com/resources/articles/articles-index/touch-mode
http://y-anz-m.blogspot.com/2010/08/androidthe-world-of-listview-item.html

そのため、choiceModeがある。ただ、choiceModeを指定するときは、行のレイアウトにデフォルトではandroid.R.layout.simple_list_item_single_choiceを使う。
これは、チェックボックスやラジオボタンのついたTextView。
sdk/platforms/android-x/data/res/layout/simple_list_single_choice.xml

なので、チェックボックス/ラジオボタンを非表示にする+上手く選択中表示をする、などの手で実現できる。
http://groups.google.com/group/android-sdk-japan/browse_thread/thread/d1b256728c759f01/4a6815f62d1f3616?hl=ja&lnk=gst&q=ListView%E3%81%AEonItemClick%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E3%81%AB%E9%96%A2%E3%81%97%E3%81%A6#4a6815f62d1f3616

ここでは言及されていないけど、R.attr.state_checkedというstateもあるので、こちらが使えれば、セレクタで選択中表示の部分は実装できるかも。

0 件のコメント: