@Override public void onClick(View v) { strInfo = mEdInputText.getText().toString(); TextContent textContent = new TextContent(State.USER, strInfo); textContents.add(textContent); adapter.notifyDataSetChanged(); send(strInfo.trim()); mEdInputText.setText(""); }
@Override public void getData(String data) { if (textContents.size() > 30) { for (int i = 0; i < 10; i++) { textContents.remove(i); } } TextContent textContent = null; try { JSONObject object = new JSONObject(data); String code = object.getString("code"); if (code.equals(State.TEXT_CONTENT)) { textContent = new TextContent(State.FRIEND, code, jsonToText(data)); textContents.add(textContent); } else if (code.equals(State.URLS_CONTENT)) { textContent = new TextContent(State.FRIEND, code, jsonToText(data), "" + object.getString("url")); System.out.println(object.getString("url")); textContents.add(textContent); } else if (code.equals(State.NEWS_CONTENT)) { JSONArray jsonArray = new JSONArray(object.getString("list")); for (int i = 0; i < jsonArray.length(); i++) { String article = new JSONObject(jsonArray.getString(i)).getString("article"); String source = "来源:" + new JSONObject(jsonArray.getString(i)).getString("source"); String detailUrl = new JSONObject(jsonArray.getString(i)).getString("detailurl"); String iconUrl = new JSONObject(jsonArray.getString(i)).getString("icon"); textContent = new TextContent( State.FRIEND, code, jsonToText(data), new News(article, source, iconUrl, detailUrl)); textContents.add(textContent); adapter.notifyDataSetChanged(); } } else if (code.equals(State.VEDIO_CONTENT)) { JSONArray jsonArray = new JSONArray(object.getString("list")); for (int i = 0; i < jsonArray.length(); i++) { String name = new JSONObject(jsonArray.getString(i)).getString("name"); String info = new JSONObject(jsonArray.getString(i)).getString("info"); String detailUrl = new JSONObject(jsonArray.getString(i)).getString("detailurl"); String iconUrl = "" + new JSONObject(jsonArray.getString(i)).getString("icon"); textContent = new TextContent( State.FRIEND, code, jsonToText(data), new ViedoData(name, info, detailUrl, iconUrl)); textContents.add(textContent); adapter.notifyDataSetChanged(); } } else if (code.equals(State.TRARN_CONTENT)) { JSONArray jsonArray = new JSONArray(object.getString("list")); for (int i = 0; i < jsonArray.length(); i++) { String trainNum = "车次:" + new JSONObject(jsonArray.getString(i)).getString("trainnum"); String start = "起始站:" + new JSONObject(jsonArray.getString(i)).getString("start"); String terminal = "到达站:" + new JSONObject(jsonArray.getString(i)).getString("terminal"); String startTime = "开车时间:" + new JSONObject(jsonArray.getString(i)).getString("starttime"); String endTime = "到达时间" + new JSONObject(jsonArray.getString(i)).getString("endtime"); String detailUrl = "详情" + new JSONObject(jsonArray.getString(i)).getString("detailurl"); String iconUrl = "" + new JSONObject(jsonArray.getString(i)).getString("icon"); textContent = new TextContent( State.FRIEND, code, jsonToText(data), new TrarnData(trainNum, start, terminal, startTime, endTime, detailUrl, iconUrl)); textContents.add(textContent); adapter.notifyDataSetChanged(); } } } catch (JSONException e) { e.printStackTrace(); } adapter.notifyDataSetChanged(); }
private void init(Context context, List<ConditionOption> groupsData) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.rebate_popupwindow_home_select_container_layout, this, true); menuList = (ListView) findViewById(R.id.rebate_lv_menu); subjectList = (ListView) findViewById(R.id.rebate_lv_subject); // FIXME 设置弹出背景 // setBackgroundDrawable(getResources().getDrawable(R.drawable.choosearea_bg_left)); if (!CheckUtil.isValidate(groupsData)) { return; } for (int i = 0; i < groupsData.size(); i++) { ConditionOption option = groupsData.get(i); groups.add(option.name); groupsKeywordArray.add(option.key); LinkedList<String> tItem = new LinkedList<String>(); if (option != null && CheckUtil.isValidate(option.sub)) { for (int j = 0; j < option.sub.size(); j++) { tItem.add(option.sub.get(j).name); childrenKeywordArray.add(option.sub.get(j).key); } childrenMap.put(i, tItem); } } if (childrenMap.size() > 0) { menuAdapter = new TextAdapter( context, groups, R.drawable.rebate_arrow_left_pressed, R.drawable.rebate_arrow_left_more); } else { menuAdapter = new TextAdapter(context, groups, R.drawable.rebate_check_pressed_icon, 0); } int selectBgId = getContext().getResources().getColor(R.color.white); int normalBgId = getContext().getResources().getColor(R.color.white_f8f8f8); menuAdapter.setViewBackgroud(selectBgId, normalBgId); menuAdapter.setTextSize(17); menuAdapter.setSelectedPositionNoNotify(menuPosition); // 默认选中0行 menuList.setAdapter(menuAdapter); menuAdapter.setOnItemClickListener( new TextAdapter.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (childrenMap.size() > 0) { childrenItem.clear(); if (childrenMap.get(position) == null) { childrenItem.addAll(new LinkedList<String>()); showString = groups.get(position); String keyword = childrenKeywordArray.get(position); if (mOnSelectListener != null) { mOnSelectListener.getValue(showString, keyword); } } else { childrenItem.addAll(childrenMap.get(position)); } subjectAdapter.notifyDataSetChanged(); } else { showString = groups.get(position); String keyword = groupsKeywordArray.get(position); if (mOnSelectListener != null) { mOnSelectListener.getValue(showString, keyword); } } } }); if (menuPosition < childrenMap.size()) childrenItem.addAll(childrenMap.get(menuPosition)); if (!CheckUtil.isValidate(childrenItem)) { subjectList.setVisibility(View.GONE); return; } subjectAdapter = new TextAdapter(context, childrenItem, R.drawable.rebate_check_pressed_icon, 0); subjectAdapter.setViewBackgroud(selectBgId, selectBgId); // 子类背景都是白色 subjectAdapter.setTextSize(15); // subjectAdapter.setSelectedPositionNoNotify(subjectPosition);//默认选中0列 subjectList.setAdapter(subjectAdapter); subjectAdapter.setOnItemClickListener( new TextAdapter.OnItemClickListener() { @Override public void onItemClick(View view, final int position) { showString = childrenItem.get(position); if (mOnSelectListener != null) { String keyword = childrenKeywordArray.get(position); mOnSelectListener.getValue(showString, keyword); } } }); if (subjectPosition < childrenItem.size()) showString = childrenItem.get(subjectPosition); // setDefaultSelect(); }