标签:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip" >
<RelativeLayout
android:id="@+id/search_frame"
android:layout_width="wrap_content"
android:layout_height="45dip"
android:layout_centerVertical="true"
android:layout_marginRight="48dip" >
<EditText
android:id="@+id/search_edit"
android:layout_width="fill_parent"
android:layout_height="32dip"
android:layout_centerVertical="true"
android:background="@drawable/search_edit_bg"
android:gravity="center_vertical"
android:paddingLeft="25dip"
android:paddingRight="22dip"
android:singleLine="true"
android:textColor="#858585"
android:textSize="15sp" />
<ImageView
android:id="@+id/search_icon"
android:layout_width="16dip"
android:layout_height="16dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dip"
android:src="@drawable/widget_uisearch_search_icon" />
<ImageView
android:id="@+id/del_btn"
android:layout_width="15dip"
android:layout_height="15dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dip"
android:src="@drawable/search_clear_pressed" />
</RelativeLayout>
<TextView
android:id="@+id/search_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@null"
android:onClick="searchOclick"
android:textColor="@drawable/search_btn_txt"
android:textSize="16sp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#dfe3e6" />
<LinearLayout
android:id="@+id/pagertabs_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical" >
<com.meetrend.customviews.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="fill_parent"
android:layout_height="50dip" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/empty_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f9f9f9"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:lineSpacingExtra="5dip"
android:text="抱 歉 \n没 有 搜 索 到 相 关 内 容"
android:textColor="#444444"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
/**
* 全局搜索 和 局部搜索(貌似还没把)
*
* */
public class AllSearchActivity extends BaseActivity implements OnClickListener {
private final static String TAG = AllSearchActivity.class.getSimpleName().toString();
private ViewPager viewPager;
private DisplayMetrics dm;
private PagerSlidingTabStrip pagertab;
private EditText searchEdit;
private TextView searchBtn;
private ImageView delBtn;
private LinearLayout emptyLayout;
private LinearLayout pagertabs_layout;
private int tablesCount;// 表单个数
private List<HashMap<String, String>> datas;
private List<List<HashMap<String, String>>> allListDatas;// 所有的列表数据
private List<Fragment> tablist;
private List<String> urlList;// 详情url集合
private SearchTabAdapter searchTabAdapter;
private String unitSearchUrl;//单元搜索路径
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_search);
initViews();
initDatas();
}
private void initDatas() {
}
private void initViews() {
emptyLayout = (LinearLayout) this.findViewById(R.id.empty_layout);
pagertabs_layout = (LinearLayout) this.findViewById(R.id.pagertabs_layout);
searchEdit = (EditText) this.findViewById(R.id.search_edit);
searchEdit.addTextChangedListener(new SearchEditWatcher());
searchBtn = (TextView) this.findViewById(R.id.search_btn);
searchBtn.setOnClickListener(this);
searchBtn.setText("取消");
delBtn = (ImageView) this.findViewById(R.id.del_btn);
delBtn.setOnClickListener(this);
delBtn.setVisibility(View.GONE);
dm = this.getResources().getDisplayMetrics();
pagertab = (PagerSlidingTabStrip) this.findViewById(R.id.tabs);
SetUiParamUtil.setTabsValue(pagertab, dm);
viewPager = (ViewPager) this.findViewById(R.id.pager);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 1:
try {
searchTabAdapter = new SearchTabAdapter(getSupportFragmentManager());
viewPager.setAdapter(searchTabAdapter);
pagertab.setViewPager(viewPager);
pagertab.setSelectPosition(0);//初始化位置并刷新
dimissDialog();
} catch (Exception e) {
e.printStackTrace();
}
break;
default:
break;
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.search_btn:
if ("搜索".equals(searchBtn.getText().toString())) {
allSearchRequestData();
} else {
this.finish();
}
break;
case R.id.del_btn:
searchEdit.setText("");
break;
default:
break;
}
}
public class SearchEditWatcher extends TextWatcherListener {
@Override
public void afterTextChanged(Editable s) {
if (!TextUtils.isEmpty(s.toString())) {
if (delBtn.getVisibility() == View.GONE) {
delBtn.setVisibility(View.VISIBLE);
}
searchBtn.setText("搜索");
} else {
if (delBtn.getVisibility() == View.VISIBLE) {
delBtn.setVisibility(View.GONE);
}
searchBtn.setText("取消");
}
}
}
public class SearchTabAdapter extends FragmentStatePagerAdapter {
public SearchTabAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int arg0) {
return tablist.get(arg0);
}
@Override
public int getItemPosition(Object object) {
return PagerAdapter.POSITION_NONE;
}
@Override
public int getCount() {
return tablist.size();
}
@Override
public CharSequence getPageTitle(int position) {
return datas.get(position).get("FName") + "(" + datas.get(position).get("FNumber") + ")";
}
}
// 全局搜索
public void allSearchRequestData() {
showDialogActivity("拼命加载中...");
MyCallBack myCallBack = new MyCallBack() {
@Override
public void onResponse(JSONObject json, JSONObject data) {
try {
JSONArray tablesArray = data.getJSONArray("ItemTable");
tablesCount = tablesArray.size();
allListDatas = new ArrayList<List<HashMap<String, String>>>();
tablist = new ArrayList<Fragment>();
urlList = new ArrayList<String>();
datas = new ArrayList<HashMap<String, String>>();
Log.i(TAG, "tablesCount="+" "+ tablesCount);
for (int i = 0; i < tablesCount; i++) {
JSONObject object = tablesArray.getJSONObject(i);
HashMap<String, String> dataMap = new HashMap<String, String>();
dataMap.put("FCode", object.getString("FCode"));
dataMap.put("FId", object.getString("FId"));
dataMap.put("FName", object.getString("FName"));
dataMap.put("FNumber", object.getString("FNumber"));
datas.add(dataMap);
JSONArray tabledatasArray = object.getJSONArray("TableData");// 数组
List<HashMap<String, String>> tempList = new ArrayList<HashMap<String, String>>();// 用于存储每个表单的数据
urlList.add(object.getString("FCode") + ".MobileForm.mdp");
for (int j = 0; j < tabledatasArray.size(); j++) {
JSONObject tabledataObj = tabledatasArray.getJSONObject(j);
HashMap<String, String> tabledataMap = new HashMap<String, String>();
tabledataMap.put("FId", tabledataObj.getString("FId"));
tabledataMap.put("FName", tabledataObj.getString("FName"));
tempList.add(tabledataMap);
}
allListDatas.add(tempList);
}
for (int i = 0; i < tablesCount; i++) {
AllSearch_Tab_Fragment fragment = new AllSearch_Tab_Fragment(i, datas, allListDatas, urlList);
tablist.add(fragment);
}
if (tablesCount > 0) {
if (pagertabs_layout.getVisibility() == View.GONE) {
pagertabs_layout.setVisibility(View.VISIBLE);
}
if (emptyLayout.getVisibility() == View.VISIBLE) {
emptyLayout.setVisibility(View.GONE);
}
mHandler.sendEmptyMessage(1);
}else {
if (pagertabs_layout.getVisibility() == View.VISIBLE) {
pagertabs_layout.setVisibility(View.GONE);
}
if (emptyLayout.getVisibility() == View.GONE) {
emptyLayout.setVisibility(View.VISIBLE);
}
dimissDialog();
}
} catch (Exception e) {
e.printStackTrace();
dimissDialog();
}
}
};
HashMap<String, String> params = new HashMap<String, String>();
params.put("keyword", searchEdit.getText().toString());
params.put(Parameter.TOKEN, App.token);
String url = App.base_url + Server.ALL_SEARCH;
VolleyHelper.getDefault().addMyCallBackRequestQueue(mHandler, url, myCallBack, params);
}
}
标签:
原文地址:http://www.cnblogs.com/linmbbest/p/4946265.html