{"id":989,"date":"2012-09-21T15:44:22","date_gmt":"2012-09-21T06:44:22","guid":{"rendered":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/?p=989"},"modified":"2012-12-27T11:39:56","modified_gmt":"2012-12-27T02:39:56","slug":"android%e3%81%aespinner%e7%94%a8key-value%e7%b0%a1%e6%98%93%e3%82%a2%e3%83%80%e3%83%97%e3%82%bf%e3%83%bc","status":"publish","type":"post","link":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/2012\/09\/21\/android%e3%81%aespinner%e7%94%a8key-value%e7%b0%a1%e6%98%93%e3%82%a2%e3%83%80%e3%83%97%e3%82%bf%e3%83%bc\/","title":{"rendered":"Android\u306eSpinner\u7528Key-Value\u7c21\u6613\u30a2\u30c0\u30d7\u30bf\u30fc"},"content":{"rendered":"<p>Android\u306e\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u3044\u3066\u3001\u5358\u7d14\u306a\u300c\u30ad\u30fc\uff1d\u5024\u300d\u69cb\u9020\u306e\u30d7\u30eb\u30c0\u30a6\u30f3\u30e1\u30cb\u30e5\u30fc\u3092\u4e00\u3064\u4f5c\u308d\u3046\u3068\u3059\u308b\u3068\u3001\u305d\u306e\u90fd\u5ea6 XXXAdapter extends ArrayAdapter&lt;String&gt; \u3092\u4f5c\u308b\u30cf\u30e1\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u6bce\u56de\u9762\u5012\u3067\u3059\u306e\u3067\u3001\u3069\u3093\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3082\u7c21\u5358\u306bSpinner\u5316\u3067\u304d\u308b\u3088\u3046\u306a<strong>KeyValueAdapter\u30af\u30e9\u30b9\uff0bKeyValueItem\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9<\/strong>\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<br \/>\nHTML\u306e&lt;select&gt;\u30bf\u30b0\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u4f7f\u3048\u307e\u3059\u3088\u3002<\/p>\n<p>\u25a0\u30b5\u30f3\u30d7\u30eb\uff1aMyObject\u30af\u30e9\u30b9<br \/>\n<code>package com.lumiere_couleur.android;<br \/>\n&nbsp;<br \/>\npublic class MyObject <strong>implements KeyValueItem<\/strong> {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;private int id;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;private String name;<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public int getId() {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return id;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public void setId(int id) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.id = id;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public String getName() {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return name;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public void setName(String name) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.name = name;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n<strong>&nbsp;&nbsp;&nbsp;&nbsp;@Override<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public long getOptionValue() {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return id;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;@Override<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public String getOptionLabel() {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return name;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/strong><br \/>\n}<\/code><\/p>\n<p>\u25a0KeyValueItem\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9<br \/>\n<code>package com.lumiere_couleur.android;<br \/>\n&nbsp;<br \/>\npublic interface KeyValueItem {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ \u9078\u629e\u80a2\u306e\u5024<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public long getOptionValue();<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ \u9078\u629e\u80a2\u306e\u8868\u793a\u6587\u5b57\u5217<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public String getOptionLabel();<br \/>\n}<\/code><\/p>\n<p>\u25a0KeyValueAdapter\u30af\u30e9\u30b9<br \/>\n<code>package com.lumiere_couleur.android;<br \/>\n&nbsp;<br \/>\nimport java.util.List;<br \/>\n&nbsp;<br \/>\nimport android.content.Context;<br \/>\nimport android.graphics.Color;<br \/>\nimport android.view.View;<br \/>\nimport android.view.ViewGroup;<br \/>\nimport android.widget.ArrayAdapter;<br \/>\nimport android.widget.TextView;<br \/>\n&nbsp;<br \/>\npublic class KeyValueAdapter extends ArrayAdapter&lt;String&gt; {<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;private List&lt;? extends KeyValueItem&gt; items;<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/**<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; * \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; *<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; * @param context<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; * @param resourceId<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; * @param items<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; *\/<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public KeyValueAdapter(Context context, int resourceId,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;? extends KeyValueItem&gt; items) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super(context, resourceId);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.context = context;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.items = items;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public int getCount() {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return items.size();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public String getItem(int position) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return items.get(position).getOptionLabel();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public long getItemId(int position) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return items.get(position).getOptionValue();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public int getPosition(long itemId) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; items.size(); i++) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (items.get(i).getOptionValue() == itemId) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return i;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;@Override<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public View getView(int position, View convertView, ViewGroup parent) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TextView label = new TextView(context);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label.setTextColor(Color.BLACK);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label.setText(items.get(position).getOptionLabel());<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return label;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n}<\/code><\/p>\n<p>\u3053\u308c\u3067\u30a2\u30c0\u30d7\u30bf\u30fc\u306e\u91cf\u7523\u304b\u3089\u9003\u308c\u3089\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android\u306e\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u3044\u3066\u3001\u5358\u7d14\u306a\u300c\u30ad\u30fc\uff1d\u5024\u300d\u69cb\u9020\u306e\u30d7\u30eb\u30c0\u30a6\u30f3\u30e1\u30cb\u30e5\u30fc\u3092\u4e00\u3064\u4f5c\u308d\u3046\u3068\u3059\u308b\u3068\u3001\u305d\u306e\u90fd\u5ea6 XXXAdapter extends ArrayAdapter&lt;String&gt; \u3092\u4f5c\u308b\u30cf\u30e1\u306b\u306a\u308a\u307e &hellip; <a href=\"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/2012\/09\/21\/android%e3%81%aespinner%e7%94%a8key-value%e7%b0%a1%e6%98%93%e3%82%a2%e3%83%80%e3%83%97%e3%82%bf%e3%83%bc\/\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Android\u306eSpinner\u7528Key-Value\u7c21\u6613\u30a2\u30c0\u30d7\u30bf\u30fc<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[81],"tags":[51],"class_list":["post-989","post","type-post","status-publish","format-standard","hentry","category-android","tag-android"],"_links":{"self":[{"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/posts\/989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/comments?post=989"}],"version-history":[{"count":15,"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/posts\/989\/revisions"}],"predecessor-version":[{"id":1000,"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/posts\/989\/revisions\/1000"}],"wp:attachment":[{"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/media?parent=989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/categories?post=989"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hello.lumiere-couleur.com\/smilkobuta\/wp-json\/wp\/v2\/tags?post=989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}