public void loadKeys(List<String> keys) { adapter.setData(keys); if (keys == null) { final File target = App.getFile(App.getInstance().getJsonFileCacheRootDir() + File.separator + "saerch_keys"); Log.i("target.getAbsolutePath()", "target.getAbsolutePath()" + target.getAbsolutePath()); try { String json = App.getFileContext(target); Log.e("test", json); org.json.JSONArray jsonArray = new JSONObject(json).getJSONArray("data"); int lenght = jsonArray.length(); keys = new ArrayList<String>(); for (int i = 0; i < lenght; i++) { keys.add(jsonArray.getString(i)); } adapter.setData(keys); } catch (Exception e) { } } }
protected void initViews(View fragmentView) { textView.setVisibility(View.GONE); if (getArguments() != null && getArguments().getInt(SearchActivity.TAG_NONE) > 1) { String text = getArguments().getString(SearchActivity.TAG_KEY); textView.setText(getString(R.string.search_none, text)); textView.setVisibility(View.VISIBLE); } adapter = new SearchKeysAdapter(); recyclerView.setAdapter(adapter); GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), COUNT_COLUMS); gridLayoutManager.setSpanSizeLookup(adapter.getSpanSizeLookup()); recyclerView.setLayoutManager(gridLayoutManager); loadHistory(); }
/** 加载搜索历史 */ private void loadHistory() { String history = spu.getHistory(); if (!TextUtils.isEmpty(history)) { adapter.setHistory(Arrays.asList(history.split(SearchActivity.SPLIT))); } }
public void onEventMainThread(HistoryClearEvent event) { adapter.setHistory(new ArrayList<String>()); }