搜索hint为多个时随机一个显示

This commit is contained in:
huangzhuanghua
2016-05-19 17:01:09 +08:00
parent 6bf1d8954b
commit f8e5c97a6e
2 changed files with 11 additions and 6 deletions

View File

@ -86,6 +86,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@ -645,14 +646,18 @@ public class MainActivity extends BaseFragmentActivity implements
@Override
public void onResponse(JSONArray response) {
if (!isDestroy) {
Type listType = new TypeToken<ArrayList<String>>() {
}.getType();
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
Gson gson = new Gson();
List<String> searchHintList = gson.fromJson(
response.toString(), listType);
if (searchHintList != null
&& !searchHintList.isEmpty()) {
searchHint = searchHintList.get(0);
if (searchHintList != null && !searchHintList.isEmpty()) {
if (searchHintList.size() == 1) {
searchHint = searchHintList.get(0);
} else {
Random random = new Random(System.currentTimeMillis());
int index = random.nextInt(searchHintList.size());
searchHint = searchHintList.get(index);
}
EventBus.getDefault().post(
new EBTopState("搜索", searchHintList
.get(0)));