码迷,mamicode.com
首页 > 其他好文 > 详细

侧拉中的”搜索“

时间:2015-11-07 23:19:37      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
以及
技术分享
技术分享
数据是动态生成的。
亮点在什么地方呢?就是说里面的输入的文本。


activity_all_search.xml   (回去多去实践下)
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <RelativeLayout
  7. android:layout_width="fill_parent"
  8. android:layout_height="50dip"
  9. android:layout_marginLeft="15dip"
  10. android:layout_marginRight="15dip" >
  11. <RelativeLayout
  12. android:id="@+id/search_frame"
  13. android:layout_width="wrap_content"
  14. android:layout_height="45dip"
  15. android:layout_centerVertical="true"
  16. android:layout_marginRight="48dip" >
  17. <EditText
  18. android:id="@+id/search_edit"
  19. android:layout_width="fill_parent"
  20. android:layout_height="32dip"
  21. android:layout_centerVertical="true"
  22. android:background="@drawable/search_edit_bg"
  23. android:gravity="center_vertical"
  24. android:paddingLeft="25dip"
  25. android:paddingRight="22dip"
  26. android:singleLine="true"
  27. android:textColor="#858585"
  28. android:textSize="15sp" />
  29. <ImageView
  30. android:id="@+id/search_icon"
  31. android:layout_width="16dip"
  32. android:layout_height="16dip"
  33. android:layout_alignParentLeft="true"
  34. android:layout_centerVertical="true"
  35. android:layout_marginLeft="5dip"
  36. android:src="@drawable/widget_uisearch_search_icon" />
  37. <ImageView
  38. android:id="@+id/del_btn"
  39. android:layout_width="15dip"
  40. android:layout_height="15dip"
  41. android:layout_alignParentRight="true"
  42. android:layout_centerVertical="true"
  43. android:layout_marginRight="5dip"
  44. android:src="@drawable/search_clear_pressed" />
  45. </RelativeLayout>
  46. <TextView
  47. android:id="@+id/search_btn"
  48. android:layout_width="wrap_content"
  49. android:layout_height="wrap_content"
  50. android:layout_alignParentRight="true"
  51. android:layout_centerVertical="true"
  52. android:background="@null"
  53. android:onClick="searchOclick"
  54. android:textColor="@drawable/search_btn_txt"
  55. android:textSize="16sp" />
  56. </RelativeLayout>
  57. <View
  58. android:layout_width="fill_parent"
  59. android:layout_height="1px"
  60. android:background="#dfe3e6" />
  61. <LinearLayout
  62. android:id="@+id/pagertabs_layout"
  63. android:layout_width="fill_parent"
  64. android:layout_height="fill_parent"
  65. android:background="#ffffff"
  66. android:orientation="vertical" >
  67. <com.meetrend.customviews.PagerSlidingTabStrip
  68. android:id="@+id/tabs"
  69. android:layout_width="fill_parent"
  70. android:layout_height="50dip" />
  71. <android.support.v4.view.ViewPager
  72. android:id="@+id/pager"
  73. android:layout_width="fill_parent"
  74. android:layout_height="fill_parent" />
  75. </LinearLayout>
  76. <LinearLayout
  77. android:id="@+id/empty_layout"
  78. android:layout_width="fill_parent"
  79. android:layout_height="fill_parent"
  80. android:background="#f9f9f9"
  81. android:gravity="center"
  82. android:orientation="horizontal"
  83. android:visibility="gone" >
  84. <TextView
  85. android:layout_width="fill_parent"
  86. android:layout_height="wrap_content"
  87. android:gravity="center"
  88. android:lineSpacingExtra="5dip"
  89. android:text="抱 歉 \n没 有 搜 索 到 相 关 内 容"
  90. android:textColor="#444444"
  91. android:textSize="14sp" />
  92. </LinearLayout>
  93. </LinearLayout>
  1. /**
  2. * 全局搜索 和 局部搜索(貌似还没把)
  3. *
  4. * */
  5. public class AllSearchActivity extends BaseActivity implements OnClickListener {
  6. private final static String TAG = AllSearchActivity.class.getSimpleName().toString();
  7. private ViewPager viewPager;
  8. private DisplayMetrics dm;
  9. private PagerSlidingTabStrip pagertab;
  10. private EditText searchEdit;
  11. private TextView searchBtn;
  12. private ImageView delBtn;
  13. private LinearLayout emptyLayout;
  14. private LinearLayout pagertabs_layout;
  15. private int tablesCount;// 表单个数
  16. private List<HashMap<String, String>> datas;
  17. private List<List<HashMap<String, String>>> allListDatas;// 所有的列表数据
  18. private List<Fragment> tablist;
  19. private List<String> urlList;// 详情url集合
  20. private SearchTabAdapter searchTabAdapter;
  21. private String unitSearchUrl;//单元搜索路径
  22. @Override
  23. protected void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.activity_all_search);
  26. initViews();
  27. initDatas();
  28. }
  29. private void initDatas() {
  30. }
  31. private void initViews() {
  32. emptyLayout = (LinearLayout) this.findViewById(R.id.empty_layout);
  33. pagertabs_layout = (LinearLayout) this.findViewById(R.id.pagertabs_layout);
  34. searchEdit = (EditText) this.findViewById(R.id.search_edit);
  35. searchEdit.addTextChangedListener(new SearchEditWatcher());
  36. searchBtn = (TextView) this.findViewById(R.id.search_btn);
  37. searchBtn.setOnClickListener(this);
  38. searchBtn.setText("取消");
  39. delBtn = (ImageView) this.findViewById(R.id.del_btn);
  40. delBtn.setOnClickListener(this);
  41. delBtn.setVisibility(View.GONE);
  42. dm = this.getResources().getDisplayMetrics();
  43. pagertab = (PagerSlidingTabStrip) this.findViewById(R.id.tabs);
  44. SetUiParamUtil.setTabsValue(pagertab, dm);
  45. viewPager = (ViewPager) this.findViewById(R.id.pager);
  46. }
  47. @Override
  48. public void handleMessage(Message msg) {
  49. super.handleMessage(msg);
  50. switch (msg.what) {
  51. case 1:
  52. try {
  53. searchTabAdapter = new SearchTabAdapter(getSupportFragmentManager());
  54. viewPager.setAdapter(searchTabAdapter);
  55. pagertab.setViewPager(viewPager);
  56. pagertab.setSelectPosition(0);//初始化位置并刷新
  57. dimissDialog();
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. }
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. @Override
  67. public void onClick(View v) {
  68. switch (v.getId()) {
  69. case R.id.search_btn:
  70. if ("搜索".equals(searchBtn.getText().toString())) {
  71. allSearchRequestData();
  72. } else {
  73. this.finish();
  74. }
  75. break;
  76. case R.id.del_btn:
  77. searchEdit.setText("");
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. public class SearchEditWatcher extends TextWatcherListener {
  84. @Override
  85. public void afterTextChanged(Editable s) {
  86. if (!TextUtils.isEmpty(s.toString())) {
  87. if (delBtn.getVisibility() == View.GONE) {
  88. delBtn.setVisibility(View.VISIBLE);
  89. }
  90. searchBtn.setText("搜索");
  91. } else {
  92. if (delBtn.getVisibility() == View.VISIBLE) {
  93. delBtn.setVisibility(View.GONE);
  94. }
  95. searchBtn.setText("取消");
  96. }
  97. }
  98. }
  99. public class SearchTabAdapter extends FragmentStatePagerAdapter {
  100. public SearchTabAdapter(FragmentManager fm) {
  101. super(fm);
  102. }
  103. @Override
  104. public Fragment getItem(int arg0) {
  105. return tablist.get(arg0);
  106. }
  107. @Override
  108. public int getItemPosition(Object object) {
  109. return PagerAdapter.POSITION_NONE;
  110. }
  111. @Override
  112. public int getCount() {
  113. return tablist.size();
  114. }
  115. @Override
  116. public CharSequence getPageTitle(int position) {
  117. return datas.get(position).get("FName") + "(" + datas.get(position).get("FNumber") + ")";
  118. }
  119. }
  120. // 全局搜索
  121. public void allSearchRequestData() {
  122. showDialogActivity("拼命加载中...");
  123. MyCallBack myCallBack = new MyCallBack() {
  124. @Override
  125. public void onResponse(JSONObject json, JSONObject data) {
  126. try {
  127. JSONArray tablesArray = data.getJSONArray("ItemTable");
  128. tablesCount = tablesArray.size();
  129. allListDatas = new ArrayList<List<HashMap<String, String>>>();
  130. tablist = new ArrayList<Fragment>();
  131. urlList = new ArrayList<String>();
  132. datas = new ArrayList<HashMap<String, String>>();
  133. Log.i(TAG, "tablesCount="+" "+ tablesCount);
  134. for (int i = 0; i < tablesCount; i++) {
  135. JSONObject object = tablesArray.getJSONObject(i);
  136. HashMap<String, String> dataMap = new HashMap<String, String>();
  137. dataMap.put("FCode", object.getString("FCode"));
  138. dataMap.put("FId", object.getString("FId"));
  139. dataMap.put("FName", object.getString("FName"));
  140. dataMap.put("FNumber", object.getString("FNumber"));
  141. datas.add(dataMap);
  142. JSONArray tabledatasArray = object.getJSONArray("TableData");// 数组
  143. List<HashMap<String, String>> tempList = new ArrayList<HashMap<String, String>>();// 用于存储每个表单的数据
  144. urlList.add(object.getString("FCode") + ".MobileForm.mdp");
  145. for (int j = 0; j < tabledatasArray.size(); j++) {
  146. JSONObject tabledataObj = tabledatasArray.getJSONObject(j);
  147. HashMap<String, String> tabledataMap = new HashMap<String, String>();
  148. tabledataMap.put("FId", tabledataObj.getString("FId"));
  149. tabledataMap.put("FName", tabledataObj.getString("FName"));
  150. tempList.add(tabledataMap);
  151. }
  152. allListDatas.add(tempList);
  153. }
  154. for (int i = 0; i < tablesCount; i++) {
  155. AllSearch_Tab_Fragment fragment = new AllSearch_Tab_Fragment(i, datas, allListDatas, urlList);
  156. tablist.add(fragment);
  157. }
  158. if (tablesCount > 0) {
  159. if (pagertabs_layout.getVisibility() == View.GONE) {
  160. pagertabs_layout.setVisibility(View.VISIBLE);
  161. }
  162. if (emptyLayout.getVisibility() == View.VISIBLE) {
  163. emptyLayout.setVisibility(View.GONE);
  164. }
  165. mHandler.sendEmptyMessage(1);
  166. }else {
  167. if (pagertabs_layout.getVisibility() == View.VISIBLE) {
  168. pagertabs_layout.setVisibility(View.GONE);
  169. }
  170. if (emptyLayout.getVisibility() == View.GONE) {
  171. emptyLayout.setVisibility(View.VISIBLE);
  172. }
  173. dimissDialog();
  174. }
  175. } catch (Exception e) {
  176. e.printStackTrace();
  177. dimissDialog();
  178. }
  179. }
  180. };
  181. HashMap<String, String> params = new HashMap<String, String>();
  182. params.put("keyword", searchEdit.getText().toString());
  183. params.put(Parameter.TOKEN, App.token);
  184. String url = App.base_url + Server.ALL_SEARCH;
  185. VolleyHelper.getDefault().addMyCallBackRequestQueue(mHandler, url, myCallBack, params);
  186. }
  187. }





侧拉中的”搜索“

标签:

原文地址:http://www.cnblogs.com/linmbbest/p/4946265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!