{"id":290,"date":"2020-03-25T11:09:14","date_gmt":"2020-03-25T03:09:14","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=290"},"modified":"2020-05-19T13:59:18","modified_gmt":"2020-05-19T05:59:18","slug":"autocompletetextview-%e5%a2%9e%e5%8a%a0%e8%b3%87%e6%96%99","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/autocompletetextview-%e5%a2%9e%e5%8a%a0%e8%b3%87%e6%96%99\/","title":{"rendered":"AutoCompleteTextView \u589e\u52a0\u8cc7\u6599"},"content":{"rendered":"<h3>1.\u5c0e\u5165Gson\u8207okhttp<\/h3>\n<pre><code class=\"language-Gradle line-numbers\">dependencies {\n    implementation \"com.squareup.okhttp3:okhttp:4.3.1\"\n    implementation \"com.google.code.gson:gson:2.8.6\"\n}\n<\/code><\/pre>\n<h3>2.\u7a0b\u5f0f\u78bc<\/h3>\n<pre><code class=\"language-Java line-numbers\">public class MainActivity extends AppCompatActivity {\n\nprivate List&lt;String&gt; cities;\n\n@Override\nprotected void onCreate(@Nullable Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n\n    AutoCompleteTextView textView = findViewById(R.id.multiAutoCompleteTextView);\n    cities = new ArrayList&lt;&gt;();\n    ArrayAdapter&lt;String&gt; arrayAdapter = new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_activated_1, cities);\n    textView.setAdapter(arrayAdapter);\n\n    Request request = new Request.Builder()\n            .url(\"https:\/\/api.myjson.com\/bins\/130mpi\")\n            .build();\n\n    new OkHttpClient().newCall(request).enqueue(new Callback() {\n        @Override\n        public void onFailure(@NotNull Call call, @NotNull IOException e) {\n\n        }\n\n        @Override\n        public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {\n            String json = response.body().string();\n            Gson gson = new Gson();\n            List&lt;CityModel&gt; cityModel = gson.fromJson(json, new TypeToken&lt;List&lt;CityModel&gt;&gt;(){}.getType());\n\n            for (CityModel model : cityModel) {\n                \/\/\u53d6\u5f97\u7e23\u5e02\n                String cityName = model.getCityName();\n                for (AreaModel areaModel : model.getAreaList()) {\n                    \/\/\u53d6\u5f97\u5340\u57df\n                    String areaName = areaModel.getAreaName();\n                    \/\/\u5408\u6210\u7e23\u5e02\u8207\u5340\u57df\n                    String cityData = cityName + areaName;\n                    cities.add(cityData);\n                }\n            }\n        }\n    });\n}\n}\n<\/code><\/pre>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>1.\u5c0e\u5165Gson\u8207okhttp dependencies { implementation &#8220;com.squa &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[30],"tags":[13,31,14],"class_list":["post-290","post","type-post","status-publish","format-standard","hentry","category-autocompletetextview","tag-android","tag-autocompletetextview","tag-java"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=290"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/290\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/290\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}