/**
 * 
 */
package com.qiyou.mb.android.ui.fragments;

import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.InputType;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter.ViewBinder;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

import com.google.gson.JsonSyntaxException;
import com.loopj.android.http.RequestParams;
import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.R;
import com.qiyou.mb.android.beans.Track;
import com.qiyou.mb.android.beans.basic.Activity_bean;
import com.qiyou.mb.android.beans.basic.GEOaddress;
import com.qiyou.mb.android.beans.basic.Group_bean;
import com.qiyou.mb.android.beans.basic.Note;
import com.qiyou.mb.android.beans.basic.Track_bean;
import com.qiyou.mb.android.beans.basic.User_bean;
import com.qiyou.mb.android.utils.NoScrollGridView;
import com.qiyou.mb.android.utils.QCursorAdapter;
import com.qiyou.mb.android.utils.QSimpleAdapter;
import com.qiyou.mb.android.utils.Utils;
import com.qiyou.mb.android.utils.enums.BBSCate;
import com.qiyou.mb.android.utils.enums.TrackAvStatus;
import com.qiyou.mb.android.utils.enums.TrackType;
import com.qiyou.mb.android.utils.enums.WebQueryCate;
import com.qiyou.mb.android.utils.image.ImageGridAdapter;
import com.qiyou.mb.android.utils.log.QLog;
import com.qiyou.mb.android.utils.server.RestMethods;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//import android.widget.ImageView;

/**
 * @author mwang
 * 
 */
public class WebList_fragment extends TrackMap_fragment/* TrackList_fragment *//* TrackingBasic_fragment *//*
																											 * Querybase_fragment
																											 * implements
																											 * LoaderCallbacks
																											 * <
																											 * Cursor
																											 * >
																											 */{

	@Override
	public void setFTag() {
		TAG = "com.qiyou.WebList_fragment";
		// FirstTabTextColor= getResources().getColorStateList(R.color.red);
		// FirstTabBackGround=R.drawable.icon_clouds;
	}

	public static String getFTag() {
		return "com.qiyou.WebList_fragment";
	}

	@Override
	public String getCurrentTag() {
		activity.updateActionBarTitle(R.string.frg_trackWeb);
		return "com.qiyou.WebList_fragment";

	}

	private boolean isFirstCreate = false;
	protected Cursor cursor = null;
	protected QCursorAdapter adapter;
	// protected MainActivity activity;
	private ProgressDialog progressDialog;
	// private Handler handler ;

	// TextView noRec ;
	// private ListView lv = null;
	// protected ListView lvWeb = null;
	// ListView lvWeb = null;
	// ListView lvWeb = null;
	// ListView lvWeb =null;
	// ListView lvWeb = null;

	// private ImageButton btn_webquery;
	private ImageView btn_webquery;

	private CheckBox chk_web_pic;
	// private CheckBox chk_my_tracks;
	// private CheckBox chk_my_nearby;
	boolean isShowPic = true;
	private boolean isShowMytrackOnly;
	private boolean isShowMyNearbyOnly;

	private QSimpleAdapter lvAdapter;

	protected TextView txtNote;

	private final int STRLNG = 30;

	private ArrayList<Map<String, String>> tmpData;

	private ListviewOnScroll listViewOnScroll = new ListviewOnScroll();

	// for web sp input
	private List<String> cateList = null; // Arrays.asList(Cates);
	private String[] totalCates = { "默认", "周边", "地区", "关键字", "我的", "驴友", "编号",
			"骑行", "路书", "徒步", "机动", "积分", "活动相关", "队伍相关", "软件使用", "车辆装备",
			"问题反馈", "骑行天地", "跑友交流", "徒步户外" };
	private String[] firstCate = {}; // {
										// "默认","\(firstItem)","我的","软件使用","活动相关","队伍相关",
										// "车辆装备","问题反馈"}
	private ArrayAdapter<?> spAdapterWeb;
	private List<String> totalList;
	private String BBSCity = "";

	// private SwipeRefreshLayout mSwipeLayout;

	// private TextView txt_swip_refrsh ;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (activity == null) {
			activity = (com.qiyou.mb.android.ui.MainActivity) getActivity();
		}
		firstLoad = true;
		isFirstCreate = true;
		if (activity != null && activity.app != null) {
			webTrackType = activity.app.getLastTracktype();
			// IL= new com.qiyou.mb.android.utils.ImageLoader(activity);
		}
		IL = new com.qiyou.mb.android.utils.ImageLoader(getActivity());

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		vContainer = inflater.inflate(R.layout.web_list, container, false);

		spWebInputType = (Spinner) vContainer
				.findViewById(R.id.sp_Web_inputType);

		initialView();

		// showCategoryList(cateLv,null);

		return vContainer;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		// this.setSelectedTab();
		// processTabQuery();

		// getLoaderManager().initLoader(0, null, this);

	}

	@Override
	protected void initialView() {
		firstLoad = true;

		txt_webinput = (EditText) vContainer.findViewById(R.id.txt_webinput);

		btn_webquery = (ImageView) vContainer.findViewById(R.id.btn_WebQuery);
		btn_webquery.setOnClickListener(ButtonOnClickListener);

		chk_web_pic = (CheckBox) vContainer.findViewById(R.id.fm_chk_web_pic);

		chk_web_pic.setOnCheckedChangeListener(m_checkboxListener);
		isShowPic = /* isShowPic|| */Utils.getNetworkType(activity) == QiYouConstant.NETWORK_TYPE_WIFII;
		chk_web_pic.setChecked(!isShowPic);
		txtNote = (TextView) vContainer.findViewById(R.id.txtNotice);
		initialTabSpIndex();
		initialWebInput();
		// initWebQueryTypeSpinWeb();
		initialTabhost();
		initialLoadingMore();
		getQueryCate();

	}

	/*
	 * void initialBBSWebListView(int viewId){ lvWeb
	 * =(ListView)vContainer.findViewById(viewId);
	 * lvWeb.setVisibility(View.VISIBLE);
	 * lvWeb.setOnItemClickListener(itemListener); lvWeb.setOnTouchListener(new
	 * OnTouchListener() {
	 * 
	 * @Override public boolean onTouch(View v, MotionEvent event) {
	 * Utils.hideSoftKeyboard(activity); return false; } });
	 * 
	 * lvWeb.setOnScrollListener( listViewOnScroll); }
	 */
	@Override
	void initialWebListView(int viewId) {
		lvWeb = (ListView) vContainer.findViewById(viewId);
		if (lvWeb == null) {
			return;
		}
		lvWeb.setVisibility(View.VISIBLE);
		lvWeb.setOnItemClickListener(itemListener);
		lvWeb.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				Utils.hideSoftKeyboard(activity);
				return false;
			}
		});

		if (ll_loadmore == null) {
			initialLoadingMore();
			loadingMore.setText(R.string.loadmore_complete);
			loadingImg.setBackgroundResource(R.drawable.icon_stop);
		}
		lvWeb.setOnScrollListener(listViewOnScroll);
		lvWeb.removeFooterView(ll_loadmore);
		lvWeb.addFooterView(ll_loadmore);
	}

	@SuppressWarnings("unchecked")
	void initialTabSpIndex() {
		if (activity.app.tabSpIndex != null) {
			return;
		}
		if (!TextUtils.isEmpty(QiYouConstant.PV_LAST_BBS_CATE)) {
			activity.app.tabSpIndex = (HashMap<String, Integer>) Utils
					.getGsonObject(QiYouConstant.PV_LAST_BBS_CATE,
							HashMap.class);

		} else {
			activity.app.tabSpIndex = new HashMap<String, Integer>(); // default
																		// selected
																		// item
			activity.app.tabSpIndex.put("0", 0);
			activity.app.tabSpIndex.put("1", 0);
			activity.app.tabSpIndex.put("2", 1);
			activity.app.tabSpIndex.put("3", 1);
			activity.app.tabSpIndex.put("4", 0);
		}

		tabSpIndexValue = new HashMap<Integer, Map<Integer, String>>();
		HashMap<Integer, String> tmp = new HashMap<Integer, String>();
//		tmp.put(0, "");
//		tabSpIndexValue.put(0, tmp);
		tmp = new HashMap<Integer, String>();
		tmp.put(3, "");
		tmp.put(4, "");
		tmp.put(5, "");
		tmp.put(6, "");
		tabSpIndexValue.put(1, tmp);
		tmp = new HashMap<Integer, String>();
		tmp.put(2, "");
		tmp.put(3, "");
		tmp.put(5, "");
		tabSpIndexValue.put(2, tmp);
		tmp = new HashMap<Integer, String>();
		tmp.put(2, "");
		tmp.put(3, "");
		tmp.put(5, "");
		tabSpIndexValue.put(3, tmp);
		tmp = new HashMap<Integer, String>();
		tmp.put(2, "");
		tmp.put(3, "");
		tmp.put(5, "");
		tabSpIndexValue.put(4, tmp);
	}

	@TargetApi(Build.VERSION_CODES.GINGERBREAD)
	void getQueryCate() {

		if (spWebInputType == null) {

			return;
		}

		// String[] Cates = {};
		// List<String> a = Arrays.asList(totalCates);

		try {

			// totalList = (ArrayList<String>) Arrays.asList(totalCates);

			// List<String> totalList2 =
			// (List<String>)Arrays.asList(totalCates);
			// totalList = (ArrayList<String>) totalList2;
			totalList = (List<String>) Arrays.asList(totalCates);

		} catch (Exception e) {
			e.printStackTrace();
			QLog.getLogger().d(TAG, e.getMessage());
		}
		switch (currentTab) {
		case 0:
			BBSCity = activity.app.user.getUserbean().getGeo().getCityName(); // .getGeo().getCityName();
			if (BBSCity == null || TextUtils.isEmpty(BBSCity)) {
				BBSCity = "地方论坛";

			}
			;

			// if (!totalList.contains(BBSCity)){
			// totalCates +=[BBSCity]; //totalList.add(totalList.size(), city);
			// }

			String[] bbsCates = { "默认", BBSCity, "我的", "软件使用", "骑行天地", "跑友交流",
					"徒步户外", "活动相关", "队伍相关", "车辆装备", "问题反馈" };
			cateList = Arrays.asList(bbsCates);

			break;
		case 1:
			String[] shareCates = { "我的", "默认", "周边", "地区", "关键字", "驴友", "编号",
					"骑行", "路书", "徒步", "机动" };
			cateList = Arrays.asList(shareCates);

			break;
		case 2:
			String[] groupCates = { "默认", "周边", "地区", "关键字", "我的", "编号" };
			cateList = Arrays.asList(groupCates);
			break;
		case 3:
			String[] actCates = { "默认", "周边", "地区", "关键字", "我的", "编号" };
			cateList = Arrays.asList(actCates);
			break;
		case 4:
			String[] userCates = { "默认", "周边", "地区", "关键字", "驴友", "编号" };
			cateList = Arrays.asList(userCates);
			break;

		}

		// 将可选内容与ArrayAdapter连接起来
		// ArrayAdapter<?>
		spAdapterWeb = new QArrayAdapter(activity, R.layout.myspinner, cateList) {
			@Override
			public View getDropDownView(int position, View convertView,
					ViewGroup parent) {
				TextView v = (TextView) super.getView(position, convertView,
						parent);
				// v.setMinimumHeight((int) (200*
				// getResources().getDisplayMetrics().density));

				v.setBackgroundResource(R.drawable.linearlayout_horizontal);

				// v.setTextAppearance(activity, R.style.ll_text_view_1);
				v.setPadding(5, 8, 5, 8);
				int selected = spWebInputType.getSelectedItemPosition();
				if (position == selected) {
					v.setTypeface(null, Typeface.BOLD);
					v.setBackgroundResource(R.drawable.head_linearlayout);
				}
				//
				// v.getPaint().setFlags(0);
				// v.setTypeface(null, Typeface.BOLD);
				// LayoutParams lp = new LayoutParams();

				v.setLayoutParams(new android.widget.AbsListView.LayoutParams(
						LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
				return v;
			}
		};// ArrayAdapter.createFromResource( activity,R.array.webInputType,
			// R.layout.thinspinner);

		// 设置下拉列表的风格
		spAdapterWeb.setDropDownViewResource(R.layout.spinner_item);

		// 将adapter2 添加到spinner中
		spWebInputType.setAdapter(spAdapterWeb);
		// int type = activity.app.getLastTracktype(); //设置首选
		// spWebInputType.setSelection(type);
		isSwitchWebInputOnly = true; // whe back from other fragment, no query
		spWebInputType.setOnItemSelectedListener(null);
		try {
			setSpSelection();
		} catch (Exception er) {

		}
		spWebInputType
				.setOnItemSelectedListener(new SpinnerXMLSelectedListener());
		// setSpSelection();
	}

	class QArrayAdapter extends ArrayAdapter<String> {

		public QArrayAdapter(Context context, int textViewResourceId,
				List<String> cateList) {
			super(context, textViewResourceId, cateList);
			// TODO Auto-generated constructor stub
		}

		/*
		 * @Override public View getDropDownView(int position, View cnvtView,
		 * ViewGroup prnt){ LayoutInflater inflater =
		 * activity.getLayoutInflater(); View spinnerItem = inflater.inflate(
		 * R.layout.spinner_item, null);
		 * 
		 * TextView mytext=
		 * (TextView)spinnerItem.findViewById(android.R.id.text1);
		 * mytext.setText(cateList.get(position));
		 * 
		 * //int selected = Spinner. int selected =
		 * spWebInputType.getSelectedItemPosition(); if(position == selected){
		 * spinnerItem.setBackgroundColor(Color.BLUE); } return spinnerItem;
		 * 
		 * }
		 */

	}

	private int lastSelectedCateId = -1;

	void webSpinnerSelected(int spID) {

//		if (lastSelectedCateId == spID) {
//			return;
//		}

		setNote();

//		lastSelectedCateId = spID;

		Map<Integer, String> tmp = tabSpIndexValue.get(Integer
				.valueOf(currentTab));// new HashMap<Integer,String>();
		String oldV = "";
		if (tmp != null) {
			oldV = tmp.get(Integer.valueOf(spID));
			txt_webinput.setText(oldV);
		}

		activity.app.tabSpIndex.put(String.valueOf(currentTab), spID);
		WebQueryCate wq = getSelectedCate();
		/*
		 * String selectedItem = spAdapterWeb.getItem(spID).toString();
		 * WebQueryCate wq = WebQueryCate.LATEST;
		 * 
		 * int cateIndex = totalList.indexOf(selectedItem); // wq =
		 * WebQueryCate.valueOf(cateIndex); if (cateIndex == -1){
		 * if(BBSCity.equalsIgnoreCase(selectedItem)){ wq = WebQueryCate.CITY; }
		 * }else { wq = WebQueryCate.values()[cateIndex]; }
		 */
		txt_webinput.setVisibility(View.VISIBLE);
		btn_webquery.setVisibility(View.VISIBLE);
		switch (wq) {
		case GEO:

			if (TextUtils.isEmpty(oldV)) {
				txt_webinput.setText(QiYouConstant.PV_LAST_CITY);
			}
			txt_webinput.setInputType(InputType.TYPE_CLASS_TEXT);
			break;
		case KEYWORD:

			txt_webinput.setHint("请输入关键字");
			// txt_webinput.setText("");
			txt_webinput.setInputType(InputType.TYPE_CLASS_TEXT);

			break;
		case USER:

			txt_webinput.setHint("请输入用户名");
			// txt_webinput.setText("");
			txt_webinput.setInputType(InputType.TYPE_CLASS_TEXT);
			break;
		case SVRNO:

			txt_webinput.setHint("请输入编号");
			// txt_webinput.setText("");
			txt_webinput.setInputType(InputType.TYPE_CLASS_NUMBER);
			break;
		default:
			btn_webquery.setVisibility(View.GONE);
			txt_webinput.setVisibility(View.GONE);

			/*
			 * if (isSwitchWebInputOnly){ isSwitchWebInputOnly = false; if
			 * (isFirstCreate){ //解决 首次创建时 不响应 cate item changed isFirstCreate =
			 * false; }else{ return; } }
			 */
			if (lastSelectedCateId == spID) {
				return;
			}
			
			lastSelectedCateId = spID;
			
			if (!firstLoad) {
				doQuery();
			} else {
				firstLoad = false;
			}
			break;
		}

	}

	/*
	 * void initialTabSpIndex(){
	 * 
	 * 
	 * initWebQueryTypeSpinWeb();
	 * 
	 * }
	 */
	// @Override
	// void mapViewOnActivityCreated(){
	//
	// }
	@Override
	void reNewShareOverflay() {
		super.reNewShareOverflay();
	}

	@Override
	void trackOnActivityCreated() {
		// locData = new LocationData();
	}

	CheckBox.OnCheckedChangeListener m_checkboxListener = new CheckBox.OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			// TODO Auto-generated method stub
			switch (buttonView.getId()) {
			case R.id.fm_chk_web_pic:
				isShowPic = !chk_web_pic.isChecked();
				// doWebTrackQuery();
				break;
			case R.id.fm_chk_show_pic:
				doQuery();
				break;
			case R.id.fm_chk_show_map:
				doQuery();
				break;

			}

		}

	};

	void initialWebInput() {
		lastWebQueryPara = "";
		lastActQueryPara = "";
		lastGrpQueryPara = "";
		lastLiveQueryPara = "";
		pageNo = 1;

	}

	String webTab;// 活动，队伍，用户...;
	String actTab;// "活动";
	String grpTab;// "队伍";
	String memberTab;// "驴友";
	String shareTab;// "分享";
	// String cloudTab;
	String bbsTab; // bbs
	TabHost.TabSpec tabTrack, tabAct, tabGrp, tabUser, tabBbs, tabLive,
			tabRoadbook;

	protected void initialTabhost() {
		bbsTab = getResources().getString(R.string.tab_bbs);// "云端";
		// cloudTab =getResources().getString(R.string.tab_cloud);//"云端";
		shareTab = getResources().getString(R.string.tab_share);// "分享";
		actTab = getResources().getString(R.string.tab_act);// "活动";
		grpTab = getResources().getString(R.string.tab_group);// "队伍";
		memberTab = getResources().getString(R.string.tab_users);// "驴友";

		tabhost = (TabHost) vContainer.findViewById(R.id.queryTabhost);
		if (tabhost == null)
			return;
		tabhost.setup();

		creatTabs();
		addTabs();

		initialTabhostStyle(tabhost);

		tabhost.setOnTabChangedListener(new OnTabChangeListener() {
			@Override
			public void onTabChanged(String tabId) {

				onMyTabChanged(tabId);

			}
		});

	}

	void creatTabs() {

		// tabhost.getTabWidget().setStripEnabled(false);
		tabTrack = tabhost.newTabSpec(shareTab);
		// t1.setIndicator(shareTab);
		tabTrack.setContent(R.id.tab_webquery);

		tabTrack.setIndicator(shareTab/*
									 * , getResources().getDrawable(R.drawable.
									 * icon_upload,null)
									 */);

		tabAct = tabhost.newTabSpec(actTab);
		tabAct.setIndicator(actTab/*
								 * ,
								 * getResources().getDrawable(R.drawable.icon_star
								 * ,null)
								 */);
		tabAct.setContent(R.id.tab_activity);

		tabGrp = tabhost.newTabSpec(grpTab);
		tabGrp.setIndicator(grpTab/*
								 * ,
								 * getResources().getDrawable(R.drawable.icon_group
								 * ,null)
								 */);
		tabGrp.setContent(R.id.tab_group);

		tabUser = tabhost.newTabSpec(memberTab);
		tabUser.setIndicator(memberTab/*
									 * , getResources().getDrawable(R.drawable.
									 * icon_user,null)
									 */);
		tabUser.setContent(R.id.tab_members);

		tabBbs = tabhost.newTabSpec(bbsTab);
		tabBbs.setIndicator(bbsTab/*
								 * ,
								 * getResources().getDrawable(R.drawable.icon_user
								 * ,null)
								 */);
		tabBbs.setContent(R.id.tab_bbs);

		/*
		 * t1=getTab(shareTab, R.drawable.icon_share ,R.id.tab_webquery);
		 * t2=getTab(actTab, R.drawable.icon_star ,R.id.tab_activity);
		 * t3=getTab(grpTab, R.drawable.icon_group ,R.id.tab_group);
		 * t4=getTab(memberTab, R.drawable.icon_user ,R.id.tab_members);
		 */

	}

	void addTabs() {
		// tabTrak,tabAct,tabGrp,tabUser,tabBbs
		tabhost.addTab(tabBbs);
		tabhost.addTab(tabTrack);
		tabhost.addTab(tabAct);
		tabhost.addTab(tabGrp);
		tabhost.addTab(tabUser);
		// tabhost.getTabWidget().setStripEnabled(true);

	}

	// 条目上单击处理方法.
	int selectedTrackItem = -1;
	int selectedActItem = -1;
	int selectMemberItem = -1;
	int selectActShareItem = -1;
	int selectGroupItem = -1;
	int selectedBBSItem = -1;
	// boolean isActShareQuery=false;
	boolean isShareQuery = false;
	boolean canclick = true;
	Handler handler;

	OnItemClickListener itemListener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {

			// QLog.getLogger().d(dTAG,
			// String.format("adapter count %s,postion is %s",
			// parent.getCount(),position));

			if (parent.getCount() == position + 1 || !canclick)
				return;
			canclick = false;

			lastIndexOnMore = -1;
			// isLoadMoreIndex =false;
			selectedTrackItem = position;
			selectedActItem = position;
			selectMemberItem = position;
			selectActShareItem = position;
			selectedBBSItem = position;
			if (isWebTrackQuery || isShareQuery) {

				// Track track =showWebTrackDetail(position);
				showWebTrack(getWebTrackDetail(position));
				canclick = true;
				return;
			}

			if (isActivityQuery) {

				// do activity query clicked
				showActivityDetail(position);
				canclick = true;
				return;
			}

			if (isMemberQuery) {

				// do activity query clicked
				showMemberDetail(position);
				canclick = true;
				return;
			}

			if (isGroupQuery) {
				showGroupDetail(position);
				canclick = true;
				return;
			}

			if (isBBSQuery) {
				showNoteDetail(position);
				canclick = true;
				return;
			}
		}

	};

	@Override
	void loadingMore() {

		// QLog.getLogger().d(dTAG, "------ can loading more 2  .. " +
		// canLoadingMore);

		isLoadingMore = true;
		// isLoadMoreIndex=true;
		lastIndexOnMore = visibleLastIndex;
		if (this.isWebTrackQuery) {
			lastWebQueryPara = "";
			pageNo++;
			doWebTrackQuery();
		} else if (this.isActivityQuery) {
			lastActQueryPara = "";
			pageNo++;
			doActQuery();
		} else if (isMemberQuery) {
			lastMemberQueryPara = "";
			pageNo++;
			doUserQuery();
		} else if (isGroupQuery) {
			lastGrpQueryPara = "";
			pageNo++;
			doGroupQuery();
		} else if (isBBSQuery) {
			// lastGrpQueryPara="";
			pageNo++;
			doBBSQuery();

		}

	}

	boolean validInput() {
		if (this.spWebInputType == null || txt_webinput == null)
			return true;

		if (txt_webinput.getVisibility() == View.VISIBLE) {
			if (TextUtils.isEmpty(txt_webinput.getText())) {
				txt_webinput.setSelected(true);
				if (mSwipeLayout != null) {
					mSwipeLayout.setRefreshing(false);
				}
				return false;
			}
		}
		return true;

	}

	List<Map<String, String>> trackData;
	List<Map<String, String>> actData;
	List<Map<String, String>> grpData;

	@Override
	public void initialWebQuery() {

		pageNo = 1;
		if (!validInput()) {
			return;
		}
		if (this.isActivityQuery) {
			this.actData = null;
			pageNo = 1;
			lastActQueryPara = "";
			doActQuery();
		} else if (this.isWebTrackQuery) {
			lastWebQueryPara = "";
			this.pageNo = 1;
			this.trackData = null;
			doWebTrackQuery();
		} else if (isMemberQuery) {
			lastMemberQueryPara = "";
			pageNo = 1;
			this.userData = null;

			doUserQuery();
		} else if (isGroupQuery) {
			lastGrpQueryPara = "";
			pageNo = 1;
			this.grpData = null;

			doGroupQuery();
		} else if (isBBSQuery) {
			lastNoteQueryPara = "";
			pageNo = 1;
			this.bbsData = null;

			doBBSQuery();
		}
		if (spWebInputType == null) {
			return;
		}
		// when query remember the webinput query parameters for currenttab
		if (txt_webinput.getVisibility() == View.VISIBLE){
			Map<Integer, String> tmp = new HashMap<Integer, String>();
			tmp.put(spWebInputType.getSelectedItemPosition(), txt_webinput
				.getText().toString());
			tabSpIndexValue.put(currentTab, tmp);// remember the currentTab,and its
												// selected webinput sp's item
												// and value.
			activity.app.tabSpIndex.put(String.valueOf(currentTab),
				this.spWebInputType.getSelectedItemPosition());// remember the
																// current tab's
		}														// sp item
	}

	@Override
	public void doQuery() {
		if (!validInput()) {

			return;
		}
		switchTabOptions(currentTab);
		this.initialWebQuery();

	}

	// ---------------------begin web track query-----------------------

	/*
	 * int pageNo=1; int pageSize=10; List<Map<String, String>> trackData;
	 */
	void doWebTrackQuery() {
		Utils.hideSoftKeyboard(activity);
		// noRec.setVisibility(View.GONE);
		isWebTrackQuery = true;
		// lvWeb.setVisibility(View.VISIBLE);
		// lv.setVisibility(View.GONE);
		// QLog.getLogger().d(dTAG, TAG+"------begin web query--------- ");

		// getJsonWs(buildQueryParames(),"mb/track/list/"+pageNo);
		// lastWebQueryPara

		if (this.firstLoad && !TextUtils.isEmpty(lastWebQueryPara)) {
			// QLog.getLogger().d(dTAG,
			// String.format("firstLoad %s,lastWebQueryPara %s  ",
			// firstLoad,lastWebQueryPara));
			return;
		}
		RequestParams param = buildTrackQueryParames();
		if (param != null
				&& !lastWebQueryPara.equalsIgnoreCase(param.toString())) {

			// QLog.getLogger().d(dTAG, lastWebQueryPara);
			// QLog.getLogger().d(dTAG, param.toString());

			getJsonWs(param, RestMethods.TRACK_G_LIST/* "mb/track/list" */);
			lastWebQueryPara = param.toString();
			selectedTrackItem = -1;

		}

	}

	RequestParams buildTrackQueryParames() {

		// RequestParams params =buildBasicParames(pageNo,webTrackType);
		// //default to get last sport type from web?
		// TrackType tmp = TrackType.valueOf(webTrackType);

		RequestParams params = buildBasicParames(pageNo, -1);

		params.add("showpic", String.valueOf(isShowPic));
		params.add("swidth", String.valueOf(QiYouConstant.PV_INT_SCREEN_WIDTH));
		params.add("sheight",
				String.valueOf(QiYouConstant.PV_INT_SCREEN_HEIGHT));
		params.add("isMyOnly", String.valueOf(isShowMytrackOnly));

		return params;
	}

	@Override
	void processTrackJsonArray(JSONArray jsonArrary) {

		/* trackData = getWebTrackList( jsonArrary); */

		// trackData = initialListData( trackData );
		// trackData.addAll(getWebTrackList( jsonArrary));
		trackData = getListData(trackData, getWebTrackList(jsonArrary));

	
		if (!isLiveQuery) {
			showNoRecText(trackData.size() == 0);
			showWebTrackListData(trackData);
		}
		// QLog.getLogger().e(dTAG,
		// String.format("trackPageNo is%s, actual pageno is %s ",pageNo,trackData.size()/pageSize));

		/*
		 * if( lvAdapter !=null){ lvAdapter.notifyDataSetChanged(); }else{
		 * showWebTrackListData(trackData); }
		 */

		/*
		 * SimpleAdapter is meant for static data, so your performance may vary.
		 * The best solution is probably to switch to a different type of
		 * adapter, such as ArrayAdapter, or make a new SimpleAdapter every time
		 * you change the dataset
		 */

	}
	void showLive() {}
	List<Map<String, String>> getWebTrackList(JSONArray jsonArrary) {
		List<Map<String, String>> webData = new ArrayList<Map<String, String>>();
		JSONObject jo = null;
		Track_bean tb;
		Track tr;// = new Track();
		if (jsonArrary != null)
			for (int i = 0; i < jsonArrary.length(); i++) {
				try {
					jo = jsonArrary.getJSONObject(i);
					if (jo == null)
						continue;
					// // QLog.getLogger().d(dTAG, "jsonarray:--> "
					// +jo.toString());
					tb = (Track_bean) Utils.getGsonObject(jo.toString(),
							Track_bean.class);

				} catch (JsonSyntaxException je) {
					Utils.logStackTrace(je, TAG);
					continue;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					Utils.logStackTrace(e, TAG);
					continue;
				}

				if (tb != null) {
					tr = new Track(tb);
					Map<String, String> t = new HashMap<String, String>();
					t.put("name", tb.getName());
					t.put("svrNumber", tb.getSvrNumber() + "");
					t.put("start", Utils.getFormatedTime(tb.getStartTime(),
							dateFormatDDMMYY));
					t.put("distance",
							String.format("%.2f", tb.getDistance() / 1000));
					// t.put("sportime", Utils.getTimeCnt(tb.getSportTime(),
					// true));



					float avs = tb.getType() == TrackType.GPX ? activity.app.getAVS() : tb.getAvs();

					long sptime = tb.getType() ==TrackType.GPX ? (long)( tb.getDistance() / avs *3600) : tb.getTotalTime();
					t.put("sportime", Utils.getTimeCnt(sptime, true));
					// t.put("avs", String.format("%.2f",tb.getAvs()));
					t.put("avs", String.format("%.2f", avs));

//					t.put("sportime", Utils.getTimeCnt(tb.getTotalTime(), true));
//					// t.put("avs", String.format("%.2f",tb.getAvs()));
//					t.put("avs", String.format("%.2f", tb.getTavs()));
					t.put("cal", String.format("%.2f", tb.getBurn()));
					t.put("comment", tb.getComment());
					t.put("desc",
							Utils.getShortString(tb.getDescription(), STRLNG));
					t.put("summary", "");// tb.getSummary());
					t.put("creator", tb.getCreator());
					t.put("avstatus", tb.getAvStatus().toString());

					/*
					 * String staticMapUrl
					 * =isShowPic?Utils.getBaiduStaticMapUrl(tr):""; // String
					 * staticMapUrl
					 * =Utils.getBaiduStaticUrlFromServer(tb.getSvrNumber()); //
					 * QLog.getLogger().d(dTAG,
					 * " static map url is: "+staticMapUrl); //
					 * QLog.getLogger().i(dTAG,
					 * " static map url is: "+staticMapUrl); t.put("staticmap",
					 * staticMapUrl );
					 */

					try {
						t.put("userName", jo.getString("userName"));

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						Utils.logStackTrace(e, TAG);
					}
					t.put("lastupdated", String.valueOf(tb.getLastdbTime()));
					// t.put("cloud", "云：" );
					// // QLog.getLogger().d(dTAG, "svrNumber:--> " +
					// tb.getSvrNumber());
					// // QLog.getLogger().d(dTAG, "sportime:--> " +
					// t.get("sportime")
					// +"...."+Utils.getTimeCnt(tb.getTotalTime(), true));
					// // QLog.getLogger().d(dTAG, "avs:--> " +
					// t.get("avs")+"...."+ String.format("%.2f",tb.getTavs()));
					// // QLog.getLogger().d(dTAG, "lastupdated:--> " +
					// String.valueOf(tb.getLastdbTime()));

					t.put("type", String.valueOf(tb.getType()));

					// String[] urls=tr.getWebPicList(4, true);

					String strUrls = "";
					if (isShowPic) {
						t.put("staticmap", tb.getStaticMapUrl());

						if (tb.getThumbUrls() != null)
							for (String url : tb.getThumbUrls()) {
								// // QLog.getLogger().d(dTAG, " url is" +url);
								strUrls += QiYouConstant.BASE_MD_URL + url
										+ QiYouConstant.SPLITOR;
							}
					}
					t.put("urls", strUrls);
					webData.add(t);
				}

			}

		return webData;

	}

	/*
	 * void getPicUrls(){ imgUrls= mTrack.getPicList();
	 * ValidUrls=mTrack.getValidPicList();
	 * 
	 * }
	 */

	// QSimpleAdapter lvAdapter;

	int currentRow = 0;

	protected void showWebTrackListData(List<Map<String, String>> trackData) {
		// this.btn_pagedown.setEnabled(!isLastPage);
		// this.btn_pageup.setEnabled(!isFirstPage);

		lvAdapter = new QSimpleAdapter(activity, trackData,
				R.layout.track_list_detail, new String[] { "start", "distance",
						"avs", "cal", "comment", "sportime", "summary", "name",
						"urls"
						// ,"creator"
						// ,"cloud"
						, "svrNumber", "userName", "staticmap", "avstatus" },
				new int[] { R.id.trakList_tv_starttime, R.id.trakList_tv_dist,
						R.id.trakList_tv_avs, R.id.trakList_tv_burn,
						R.id.trakList_tv_comment, R.id.trakList_tv_sportTime,
						R.id.trakList_tv_desc, R.id.trakList_tv_name,
						R.id.trakList_gridView
						// ,R.id.trakList_tv_creator
						// ,R.id.trakList_tv_cloud
						, R.id.trakList_tv_svrNo, R.id.trakList_tv_creator

						// ,R.id.trakList_tv_showGpx
						, R.id.trakList_staticMap, R.id.trakList_avStatusImg });
		currentRow = 0;
		lvAdapter.setViewBinder(new ViewBinder() {

			@Override
			public boolean setViewValue(View view, Object data,
					String textRepresentation) {
				currentRow++;
				TextView text;
				switch (view.getId()) {
				case R.id.trakList_tv_name: {
					text = (TextView) view;

					String str = "未命名";
					if (data != null) {
						str = Utils.getShortString(data.toString(), 6);
					}
					text.setText(str); // set some data
					text.setVisibility(View.VISIBLE);

					return true;
				}

				case R.id.trakList_tv_creator: { // track title
					if (!isShowMytrackOnly && data != null)
						view.setVisibility(View.VISIBLE);

					return false;
				}

				case R.id.trakList_tv_svrNo: {
					if (data != null) {
						text = (TextView) view;
						text.setText("" + data);
					}
					// QLog.getLogger().d(dTAG, " displaying server number " +
					// data.toString());
					return true;
				}

				case R.id.trakList_staticMap: {
					// TextView text = (TextView) view; // get your View
					com.qiyou.mb.android.utils.image.QimageView imgv = (com.qiyou.mb.android.utils.image.QimageView) view;
					imgv.setVisibility(View.GONE);
					if (data == null || data.toString().length() < 10)
						return true;
					// QLog.getLogger().d(dTAG, " displaying static image of " +
					// data.toString());
					IL.DisplayImage(data.toString(), imgv);
					imgv.setVisibility(View.VISIBLE);

					return true;
				}

				case R.id.trakList_tv_desc: {
					text = (TextView) view;
					String str = null;
					if (data != null) {
						str = Utils.getShortString(data.toString(), 20);
					}
					if (TextUtils.isEmpty(str))
						text.setVisibility(View.GONE);
					else {
						text.setText(str); // set some data
						text.setVisibility(View.VISIBLE);
					}
					return true;
				}

				case R.id.trakList_tv_comment: {
					// TextView text = (TextView) view; // get your View
					text = (TextView) view;

					String str = null;
					if (data != null) {
						str = Utils.getShortString(data.toString(), 20);
					}
					if (TextUtils.isEmpty(str))
						text.setVisibility(View.GONE);
					else {
						text.setText(str); // set some data
						text.setVisibility(View.VISIBLE);
					}

					return true;
				}
				case R.id.trakList_avStatusImg: {
					com.qiyou.mb.android.utils.image.QimageView imgv = (com.qiyou.mb.android.utils.image.QimageView) view;
					imgv.setVisibility(View.GONE);
					if (data == null
							|| !data.toString().equalsIgnoreCase(
									TrackAvStatus.PRIVATE.toString()))
						return true;
					// QLog.getLogger().d(dTAG,
					// " displaying available image of " + data.toString());
					imgv.setBackgroundResource(R.drawable.icon_lock);
					imgv.setVisibility(View.VISIBLE);
					return true;
				}

				case R.id.trakList_gridView: {

					// int picCnt=4;

					String[] Urls = ((String) data)
							.split(QiYouConstant.SPLITOR_KEY);
					// String[] Urls=getImages(cursor.getString(8),picCnt);
					// //pic cnt = screen.width/80
					NoScrollGridView gridView = (NoScrollGridView) view;
					gridView.setVisibility(View.GONE);
					// QLog.getLogger().d(dTAG,
					// TAG+" checking if the urls is empty.......... ");
					if (TextUtils.isEmpty((String) data))
						return true;

					if (Urls != null && Urls.length > 0) {
						// QLog.getLogger().d(dTAG,
						// TAG+" checking if the urls is empty "+(String)data);

						gridView.setVisibility(View.VISIBLE);
						gridView.setAdapter(new ImageGridAdapter(Urls, activity));
						gridView.setFocusable(false);

						// gridView.setOnItemClickListener(itemListener);
						// gridView.cursorPosition=currentRow;

						/*
						 * how to get current row of lvWeb
						 * http://stackoverflow.com
						 * /questions/17394498/android-bind
						 * -data-to-listview-without-cursor
						 * 
						 * @Override public View getView(int position, View
						 * convertView, ViewGroup parent) {
						 * 
						 * gridView.setOnItemClickListener(new
						 * AdapterView.OnItemClickListener() {
						 * 
						 * @Override public void onItemClick(AdapterView<?>
						 * parent, View view, int position, long id) { int mpos
						 * = ((NoScrollGridView)parent).cursorPosition;
						 * lvWeb.performItemClick
						 * (lvWeb.getAdapter().getView(mpos, null, null), mpos,
						 * mpos);
						 * 
						 * } });
						 */

					}

					return true;
				}

				}
				return false;
			}
		});

		// selectedTrackItem =visibleLastIndex - visibleItemCnt + 1;

		/*
		 * selectedTrackItem
		 * =lastIndexOnMore>0?lvAdapter.getCount()-pageSize:selectedTrackItem;
		 * lvWeb.addFooterView(ll_loadmore);
		 * 
		 * lvWeb.setAdapter(lvAdapter); if(lastIndexOnMore<=0){
		 * lvAdapter.setSelectItem(selectedTrackItem); }
		 * lvWeb.setSelection(selectedTrackItem);
		 */

		bindListView(lvAdapter, lvWeb, selectedTrackItem, isTrackLastPage);

		// lvWeb.setSelection(isLoadMoreIndex?visibleLastIndex -
		// visibleItemCnt-1:selectedTrackItem);

		// lvWeb.setSelection(); //设置选中项
		// adapter.setSelectItem(selectedFoodmarkItem);
		// lv.setSelection(selectedFoodmarkItem);

		// lv.smoothScrollToPosition(selectedFoodmarkItem);
		// lv.smoothScrollToPositionFromTop(selectedFoodmarkItem, 50);
	}

	/*
	 * int svrNumber; int svrTrackType; long lastupdated;
	 */

	Track getWebTrackDetail(int position) {

//		if (trackData /* lvAdapter */== null /* || this.lvAdapter.getCount()==0 */) {
//			return null;
//		}
		
		if(isWebTrackQuery && trackData == null ){
			return null;
		}
		
		if (  lvAdapter == null  || this.lvAdapter.getCount()==0  ) {
			return null;
		}
		Track track = null;

		try {
			// this.lvAdapter.setSelectItem(position);
			// this.lvAdapter.notifyDataSetInvalidated();
			// this.lvWeb.setSelection(position);
//			HashMap<String, String> localHashMap = (HashMap<String, String>) trackData
//					.get(position); // this.lvAdapter.getItem(position);
			HashMap<String, String> localHashMap = isWebTrackQuery ? (HashMap<String, String>) trackData
 					.get(position) :(HashMap<String, String>)  this.lvAdapter.getItem(position);
 					
			this.trackSvrNumber = Integer.parseInt(localHashMap
					.get("svrNumber"));
			this.svrTrackType = Integer.parseInt(localHashMap.get("type"));
			this.lastupdated = Long.parseLong(localHashMap.get("lastupdated"));
			// }catch(NumberFormatException ne ){
			// Utils.logStackTrace(ne, TAG);
			// showNotes("出错了");
			// return;
			// }
			// QLog.getLogger().d("com.qiyou", TAG +
			// " get selected trackSvrNumber:" + this. trackSvrNumber);

			// try{

			// requestTrackFromWeb();
			// long start=System.currentTimeMillis();

			// track = getTrackFromWebCache(String.valueOf(svrNumber) +
			// this.lastupdated);
			track = getTrackFromWebCache(trackSvrNumber, this.lastupdated);
			// // QLog.getLogger().d(dTAG,
			// " load track cost "+(System.currentTimeMillis()-start ));

			// if(track!=null){
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean startwp: "+mTrack_bean.getStartWp().toString());
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean endwp: "+mTrack_bean.getLastWp().toString());
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean endwp: "+mTrack_bean.getLastWp().toString());
			// track.getTrackBean().getTrkseg().clear();
			// // QLog.getLogger().d(dTAG, "  track is"+track.toString());

			// }

		} catch (NumberFormatException ne) {
			Utils.logStackTrace(ne, TAG);
			showNotes("出错了");
			return null;
		} catch (IOException localIOException) {
			Utils.logStackTrace(localIOException, TAG);
		} catch (java.lang.IndexOutOfBoundsException IndexException) {
			Utils.logStackTrace(IndexException, TAG);
		} catch (Exception er) {
			Utils.logStackTrace(er, TAG);
		}

		if ((track != null)
				&& (track.getTrackBean().getSvrNumber() == this.trackSvrNumber)) {
			return track;

		} else {
			requestTrackFromWeb(this.trackSvrNumber);
			return null;
		}
	}
	@Override
	  void  showWebTrack(Track tr){ 
		  if(tr==null)return;
		    this.activity.app.setCurrentTrack(tr,true);
//		    showDetailTrack( this.svrNumber );
		    activity.showGpxTrackDetail( tr.getTrackBean().getType().toInt() , tr.getTrackBean().getSvrNumber(), true);
	  }
	// -------------------------------------------------------------web query
	// end--------------------

	// -------------------------------------------------------------activity
	// query begin --------------------------------------

	/*
	 * int pageNo=1; List<Map<String, String>> actData;
	 */

	void doActQuery() {
		Utils.hideSoftKeyboard(activity);
		// noRec.setVisibility(View.GONE);
		isActivityQuery = true;
		// lvWeb.setVisibility(View.VISIBLE);
		// lv.setVisibility(View.GONE);
		// QLog.getLogger().d(dTAG, TAG+"------begin Act query--------- ");

		// getJsonWs(buildQueryParames(),"mb/track/list/"+pageNo);
		// lastWebQueryPara

		if (this.firstLoad && !TextUtils.isEmpty(lastActQueryPara)) {
			return;
		}
		RequestParams param = buildActQueryParames();
		if (param != null
				&& !lastActQueryPara.equalsIgnoreCase(param.toString())) {

			// QLog.getLogger().d(dTAG, lastActQueryPara);
			// QLog.getLogger().d(dTAG,
			// RestMethods.ACT_G_LIST+"?"+param.toString());

			getJsonWs(param, RestMethods.ACT_G_LIST/* "mb/activity/list" */);
			lastActQueryPara = param.toString();
			selectedActItem = -1;

		}

	}

	RequestParams buildActQueryParames() {
		RequestParams params = buildBasicParames(pageNo, -1);

		return params;
	}

	/*
	 * RequestParams buildNearByQueryParames(){ RequestParams params = new
	 * RequestParams();
	 * 
	 * // String svrNo= edSvrNo.getText().toString(); int page=1;
	 * if(isActivityQuery){ page=pageNo; //
	 * QLog.getLogger().d(dTAG," building activity nearby query...."); }else
	 * if(isGroupQuery){ page=pageNo; //
	 * QLog.getLogger().d(dTAG," building group nearby query....");
	 * 
	 * }else{ // QLog.getLogger().e(dTAG,
	 * " neither activity nore group nearby query....pls check, return null");
	 * 
	 * return null; } params.add("page", String.valueOf(page));
	 * params.add("pagesize", String.valueOf(pageSize));
	 * //QiYouConstant.PV_LAST_LAT,QiYouConstant.PV_LAST_LON
	 * params.add("lat",String.valueOf(QiYouConstant.PV_LAST_LAT));
	 * params.add("lon",String.valueOf(QiYouConstant.PV_LAST_LON));
	 * params.add("memberId"
	 * ,String.valueOf(activity.app.user.getUserbean().getId()));
	 * 
	 * if(!TextUtils.isEmpty(svrNo)){ params.add("svrNo", svrNo); }
	 * 
	 * // QLog.getLogger().d(dTAG, TAG+" web query params: "+params);
	 * 
	 * return params; }
	 */

	/*
	 * void doActNearbyQuery(){ Utils.hideSoftKeyboard(activity);
	 * noRec.setVisibility(View.GONE); isActivityQuery=true; //
	 * lvWeb.setVisibility(View.VISIBLE); // lv.setVisibility(View.GONE); //
	 * QLog.getLogger().d(dTAG, TAG+"------begin Act Nearby query--------- ");
	 * 
	 * // getJsonWs(buildQueryParames(),"mb/track/list/"+pageNo); //
	 * lastWebQueryPara
	 * 
	 * if(this.firstLoad&&!TextUtils.isEmpty(lastActQueryPara)){ return; }
	 * RequestParams param=buildNearByQueryParames(); if(param!=null &&
	 * !lastActQueryPara.equalsIgnoreCase(param.toString()) ){
	 * 
	 * // QLog.getLogger().d(dTAG, lastActQueryPara); //
	 * QLog.getLogger().d(dTAG, param.toString());
	 * 
	 * getJsonWs(param,RestMethods.ACT_G_LIST"mb/activity/nearbylist");
	 * lastActQueryPara =param.toString(); selectedActItem =-1;
	 * 
	 * }
	 * 
	 * }
	 */

	/*
	 * boolean isActFirstPage; boolean isActLastPage; void
	 * processActPageInfo(JSONObject jo) throws JSONException{
	 * 
	 * // jo.getInt("totalPages"); isActLastPage =jo.getBoolean("last");
	 * isActFirstPage =jo.getBoolean("first"); // jo.get("size");//pagesize //
	 * jo.get("totalElements"); //总数 // jo.get("numberOfElements");//返回个数 //
	 * jo.get("number");
	 * 
	 * // this.btn_pagedown.setEnabled(!isLastPage); //
	 * this.btn_pageup.setEnabled(!isFirstPage);
	 * processActJsonArray(jo.getJSONArray("content")); }
	 */

	private final String dateFormatDDMMYY = "yyyy.MM.d HH:mm";

	@Override
	void processActJsonArray(JSONArray jsonArrary) {

		tmpData = new ArrayList<Map<String, String>>();

		JSONObject jo = null;
		Activity_bean ab;

		GEOaddress startgeo, endgeo;

		if (jsonArrary != null)
			for (int i = 0; i < jsonArrary.length(); i++) {
				try {
					jo = jsonArrary.getJSONObject(i);
					if (jo == null)
						continue;
					// // QLog.getLogger().d(dTAG, "jsonarray:--> "
					// +jo.toString());
					ab = (Activity_bean) Utils.getGsonObject(jo.toString(),
							Activity_bean.class);

				} catch (JsonSyntaxException je) {
					Utils.logStackTrace(je, TAG);
					continue;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					Utils.logStackTrace(e, TAG);
					continue;
				}

				if (ab != null) {
					// tr= new Track(tb);
					Map<String, String> t = new HashMap<String, String>();
					startgeo = new GEOaddress(ab.getStartGeo());
					endgeo = new GEOaddress(ab.getEndGeo());

					t.put("name", ab.getName());
					t.put("svrNumber", ab.getSvrNumber() + "");
					t.put("startTime", Utils.getFormatedTime(ab.getStartDate(),
							dateFormatDDMMYY));
					t.put("endTime", Utils.getFormatedTime(ab.getEndDate(),
							dateFormatDDMMYY));
					t.put("description",
							Utils.getShortString(ab.getDescription(), STRLNG));

					t.put("startPlace",
							String.format("%s  %s", ab.getStartPlace(),
									startgeo.toString(",")).replace("null", ""));
					t.put("endPlace",
							String.format("%s  %s", ab.getEndPlace(),
									endgeo.toString(startgeo, ",")).replace(
									"null", ""));
					t.put("shangquan", ab.getStartGeo().getComment());
					t.put("status", ab.getStatus().toString());
					t.put("memberCnt", ab.getUserCnt() + "");
					t.put("userName", ab.getUserName());
					
					String dist = ab.getLat() > 0 && QiYouConstant.PV_LAST_LAT > 0 ?  String.format("距你  %s，",  Utils.getDistanceRange(0,ab.getLat(), ab.getLon())) : "" ;  
				    t.put("distrg",dist + getTimeLeft(ab)) ;
							
//					t.put("distrg",dist + String.format("距你  %s ， %s", Utils
//							.getDistanceRange(/* ab.getDistrange() */0,
//									ab.getLat(), ab.getLon()), getTimeLeft(ab)));

					// t.put("timeLeft", "当前距活动开始剩余时间：" + getTimeLeft(ab));
					t.put("lastupdated", ab.getLastupdated() + "");
					/*
					 * String staticMapUrl
					 * =isShowPic?Utils.getBaiduStaticMapUrl(tr):""; // String
					 * staticMapUrl
					 * =Utils.getBaiduStaticUrlFromServer(tb.getSvrNumber()); //
					 * QLog.getLogger().d(dTAG,
					 * " static map url is: "+staticMapUrl); //
					 * QLog.getLogger().i(dTAG,
					 * " static map url is: "+staticMapUrl); t.put("staticmap",
					 * staticMapUrl );
					 */

					try {
						t.put("userName", jo.getString("userName"));

					} catch (JSONException e) {
						// TODO Auto-generated catch block
						Utils.logStackTrace(e, TAG);
					}
					// t.put("lastupdated", String.valueOf(ab.getLastdbTime())
					// );
					// t.put("cloud", "云：" );
					// QLog.getLogger().d(dTAG, "svrNumber:--> " +
					// ab.getSvrNumber());
					// // QLog.getLogger().d(dTAG, "lastupdated:--> " +
					// String.valueOf(ab.getLastdbTime()));

					t.put("type", String.valueOf(ab.getType()));

					t.put("dist", String.valueOf(ab.getDistance()));
					t.put("avs", String.valueOf(ab.getAvSpeed()));
					t.put("rateLevel", String.format("%.0f", ab.getRateLevel()));
					t.put("timelong",
							ab.getAvSpeed() > 0 ? String.format("%.0f",
									ab.getDistance() / ab.getAvSpeed()) : "--");
					t.put("userCnt", String.valueOf(ab.getUserCnt()));

					// String[] urls=tr.getWebPicList(4, true);

					String strUrls = "";
					if (isShowPic) {
						/*
						 * t.put("staticmap", ab.getStaticMapUrl() );
						 * 
						 * if(tb.getThumbUrls()!=null) for(String
						 * url:tb.getThumbUrls()){ // QLog.getLogger().d(dTAG,
						 * " url is" +url);
						 * strUrls+=QiYouConstant.BASE_MD_URL+url
						 * +QiYouConstant.SPLITOR; }
						 */
					}
					t.put("urls", strUrls);
					tmpData.add(t);
				}

			}

		actData = getListData(actData, tmpData);

		showNoRecText(actData.size() == 0);

		showActData();

		// QLog.getLogger().e(dTAG,
		// String.format("pageNo is%s, actual pageno is %s ",pageNo,actData.size()/pageSize));

	}

	String getTimeLeft(Activity_bean ab) {

		// String rtformat="活动开始还有：%s天";
		String rtformat = " %s天后开始";
		String startSoon = " 即将开始";
		String startted = "已经开始";
		String expired = "已经结束";
		int days;
		if (ab.isRepeatable()) {

			long diff = ab.getStartDate() - System.currentTimeMillis();
			days = Utils.getDayscnt(diff);
			if (diff >= 0) { // not started yet
			// return prefix+ Utils.getDayscnt(diff);
				if (days > 0)
					return String.format(rtformat, days);
				else
					return startSoon;
			} else if (ab.getEndDate() > 0) {
				if (ab.getEndDate() > System.currentTimeMillis()) {
					// return startted;
				} else {
					return expired;
				}
			}

			if (ab.getDays().size() == 0) {
				return "";
			}

			Calendar c = Calendar.getInstance();
			int currentDay = c.get(Calendar.DAY_OF_WEEK) - 1;
			// int minDay=8;
			int nextDay = currentDay;
			for (int i : ab.getDays()) {
				if (nextDay < i) {
					nextDay = i;
					break;
				}

			}

			if (nextDay > currentDay) { // 本周

				days = nextDay - currentDay;

			} else { // next week
				days = 7 - currentDay + ab.getDays().get(0);
			}

			// return prefix+( days>0?(days+"天"):"");
			if (days > 0) {
				return String.format(rtformat, days);
			} else {
				return startSoon;
			}

		} else {
			if (System.currentTimeMillis() < ab.getStartDate()) {
				// return prefix+ Utils.getDayscnt(ab.getStartDate()
				// -System.currentTimeMillis() );
				days = Utils.getDayscnt(ab.getStartDate()
						- System.currentTimeMillis());
				if (days > 0) {
					return String.format(
							rtformat,
							Utils.getDayscnt(ab.getStartDate()
									- System.currentTimeMillis()));
				} else {
					return startSoon;
				}
			} else {
				if (ab.getEndDate() > 0) {
					if (ab.getEndDate() > System.currentTimeMillis()) {
						return startted;
					} else {
						return expired;
					}
				}

				return startted;
			}

		}

	}

	// QSimpleAdapter lvAdapter;

	int currentActRow = 0;

	protected void showActData() {
		// this.btn_pagedown.setEnabled(!isActLastPage);
		// this.btn_pageup.setEnabled(!isActFirstPage);

		lvAdapter = new QSimpleAdapter(activity, actData,
				R.layout.activity_list_detail, new String[] { "name",
						"svrNumber", "startTime", "endTime", "startPlace",
						"endPlace", "memberCnt", "shangquan", "description",
						"status", "type", "distrg", "dist", "avs", "rateLevel",
						"timelong", "userName"

				}, new int[] { R.id.actList_name, R.id.actList_svrNo,
						R.id.actList_starttime, R.id.actList_endtime,
						R.id.actList_startplace, R.id.actList_endplace,
						R.id.actList_memberCnt, R.id.actList_shangquan,
						R.id.actList_desc, R.id.actlist_status,
						R.id.actlist_type, R.id.actList_distRange,
						R.id.actList_dist, R.id.actList_avs,
						R.id.actList_level, R.id.actList_sportTime,
						R.id.actList_owner });

		//
		// lvWeb.setAdapter(lvAdapter);
		//
		// lvAdapter.setSelectItem(selectedActItem);
		// lvWeb.setSelection(selectedActItem);

		bindListView(lvAdapter, lvWeb, selectedActItem, isActLastPage);

		/*
		 * selectedActItem
		 * =lastIndexOnMore>0?lvAdapter.getCount()-pageSize:selectedActItem;
		 * lvWeb.addFooterView(ll_loadmore);
		 * 
		 * lvWeb.setAdapter(lvAdapter); if(lastIndexOnMore<=0){
		 * lvAdapter.setSelectItem(selectedActItem); }
		 * lvWeb.setSelection(selectedActItem);
		 */

	}

	/*
	 * int actSvrNumber; int actType; long actLastupdated;
	 */

	void showActivityDetail(int position) {
		int actSvrNumber = 0;
		Activity_bean act = null;
		if (lvAdapter == null || lvAdapter.getCount() <= position) {
			// QLog.getLogger().e(dTAG,
			// "wrong group position clicked,reurn....");
			return;
		}
		try {
			this.lvAdapter.setSelectItem(position);
			this.lvAdapter.notifyDataSetInvalidated();
			this.lvWeb.setSelection(position);
			HashMap<String, String> localHashMap = (HashMap<String, String>) this.lvAdapter
					.getItem(position);
			actSvrNumber = Integer.parseInt(localHashMap.get("svrNumber"));
			if (localHashMap.get("type") != null
					&& !localHashMap.get("type").equalsIgnoreCase("null")) {
				try {
					this.actType = Integer.parseInt(localHashMap.get("type"));
				} catch (NumberFormatException ne) {
					Utils.logStackTrace(ne, TAG);
				}
			}
			this.actLastupdated = Long.parseLong(localHashMap
					.get("lastupdated"));
			// }catch(NumberFormatException ne ){
			// Utils.logStackTrace(ne, TAG);
			// showNotes("出错了");
			// return;
			// }
			// QLog.getLogger().d("com.qiyou", TAG +
			// " get selected actSvrNumber:" + actSvrNumber);

			// try{

			// requestTrackFromWeb();
			long start = System.currentTimeMillis();

			// track = getTrackFromWebCache(String.valueOf(svrNumber) +
			// this.lastupdated);
			// act = getActFromWebCache( actSvrNumber, this.actLastupdated);
			// QLog.getLogger().d(dTAG,
			// " load act cost "+(System.currentTimeMillis()-start ));

			// if(track!=null){
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean startwp: "+mTrack_bean.getStartWp().toString());
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean endwp: "+mTrack_bean.getLastWp().toString());
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean endwp: "+mTrack_bean.getLastWp().toString());
			// track.getTrackBean().getTrkseg().clear();
			// // QLog.getLogger().d(dTAG, "  track is"+track.toString());

			// }

		} catch (NumberFormatException ne) {
			Utils.logStackTrace(ne, TAG);
			showNotes("出错了");
			return;
		}
		// catch (IOException localIOException){
		// Utils.logStackTrace(localIOException, TAG);
		// }
		catch (java.lang.IndexOutOfBoundsException IndexException) {
			Utils.logStackTrace(IndexException, TAG);
		} catch (Exception er) {
			Utils.logStackTrace(er, TAG);
		}

		if (actSvrNumber <= 0) {
			return;
		}

		// if ((act != null) && (act.getSvrNumber() == actSvrNumber)){
		// showActivity(act);
		//
		// }
		// else
		requestActFromWeb(actSvrNumber);
	}

	void requestActFromWeb(int svrNo) {
		RequestParams params = new RequestParams();
		params.add("id", String.valueOf(svrNo));
		// QLog.getLogger().d(dTAG, TAG+" web query params: "+params);
		getJsonWs(params, RestMethods.ACT_G_FIND_BY_ID/* "mb/activity/" */);
		// long l1 = System.currentTimeMillis();
		// // QLog.getLogger().d("com.qiyou", TAG +
		// " start Click item to show track detail, time is:" + l1);
		// getJsonWs(null, "mb/track/" + this.svrNumber);
		// /long l2 = System.currentTimeMillis() - l1;
		// // QLog.getLogger().d("com.qiyou", TAG + " get data from web cost:" +
		// l2);
	}

	/*
	 * void checkActUserWs(RequestParams params,String url){
	 * if(prgDialog==null)initPrgDialog(); // if(this.isAdded())
	 * prgDialog.show(); showWebDialog(); hideNotes();
	 * 
	 * QiYouApplication.get(url, params, new JsonHttpResponseHandler() {
	 * 
	 * @Override public void onSuccess(int statusCode, Header[] headers,
	 * JSONObject response) { prgDialog.hide(); // QLog.getLogger().d(dTAG, TAG+
	 * ", onSuccess(int statusCode, Header[] headers, JSONObject response) was received"
	 * );
	 * 
	 * // if (response != null) { try { checkActUserResult( response); } catch
	 * (JSONException e) { // TODO Auto-generated catch block
	 * e.printStackTrace(); }
	 * 
	 * // } } }); }
	 */

	// void checkActUserResult( JSONObject response) throws JSONException {
	//
	// }

	// ---------------------------------------------------------activity query
	// end----------------------------------------------

	// ---------------------------------------------------------member query
	// begin----------------------------------------------

	int userId;
	List<Map<String, String>> userData;

	void doUserQuery() {
		Utils.hideSoftKeyboard(activity);
		// noRec.setVisibility(View.GONE);
		isMemberQuery = true;
		// lvWeb.setVisibility(View.VISIBLE);
		// lv.setVisibility(View.GONE);
		// QLog.getLogger().d(dTAG, TAG+"------begin Member query--------- ");

		// getJsonWs(buildQueryParames(),"mb/track/list/"+pageNo);
		// lastWebQueryPara

		if (/*
			 * activity.currentAcitiviy ==null ||
			 * activity.currentAcitiviy.getSvrNumber()==0 ||
			 */
		this.firstLoad && !TextUtils.isEmpty(lastMemberQueryPara)) {
			return;
		}
		RequestParams param = buildMemberQueryParames();
		if (param != null
				&& !lastMemberQueryPara.equalsIgnoreCase(param.toString())) {

			// QLog.getLogger().d(dTAG, lastActQueryPara);
			// QLog.getLogger().d(dTAG, param.toString());

			getJsonWs(param, RestMethods.USER_G_LIST /* "mb/user/actusers" */);
			lastMemberQueryPara = param.toString();
			selectMemberItem = -1;

		}

	}

	RequestParams buildMemberQueryParames() {
		RequestParams params = buildBasicParames(pageNo, -1);
		return params;
		/*
		 * RequestParams params = new RequestParams(); //
		 * params.add("lat",String.valueOf(QiYouConstant.PV_LAST_LAT)); //
		 * params.add("lon",String.valueOf(QiYouConstant.PV_LAST_LON)); String
		 * city =webCity!=null?webCity.getText().toString().trim():null;
		 * if(!TextUtils.isEmpty(city)){ try { city
		 * =URLEncoder.encode(webCity.getText().toString(),"UTF-8");
		 * params.add("city", city); } catch (UnsupportedEncodingException e) {
		 * // TODO Auto-generated catch block e.printStackTrace(); } }
		 * params.add("page", String.valueOf(pageNo)); params.add("pagesize",
		 * String.valueOf(pageSize)); params.add("isNearby",
		 * String.valueOf(this.isShowMyNearbyOnly));
		 * 
		 * // QLog.getLogger().d(dTAG, TAG+" user query params: "+params);
		 * 
		 * return params;
		 */
	}

	void showMemberDetail(int position) {
		try {
			this.lvAdapter.setSelectItem(position);
			this.lvAdapter.notifyDataSetInvalidated();
			// this.lvWeb.setSelection(position);
			HashMap<String, String> localHashMap = (HashMap<String, String>) this.lvAdapter
					.getItem(position);
			userId = Integer.parseInt(localHashMap.get("id"));

			// this.actLastupdated =
			// Long.parseLong(localHashMap.get("lastupdated")) ;
			// }catch(NumberFormatException ne ){
			// Utils.logStackTrace(ne, TAG);
			// showNotes("出错了");
			// return;
			// }
			// QLog.getLogger().d("com.qiyou", TAG + " get selected userId:" +
			// this.userId);

			// try{

			// requestTrackFromWeb();
			long start = System.currentTimeMillis();

			// track = getTrackFromWebCache(String.valueOf(svrNumber) +
			// this.lastupdated);
			// userId = getActFromWebCache( svrNumber, this.actLastupdated);
			// QLog.getLogger().d(dTAG,
			// " load userId cost "+(System.currentTimeMillis()-start ));

			// if(track!=null){
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean startwp: "+mTrack_bean.getStartWp().toString());
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean endwp: "+mTrack_bean.getLastWp().toString());
			// // QLog.getLogger().d(dTAG,
			// "  mtrack_bean endwp: "+mTrack_bean.getLastWp().toString());
			// track.getTrackBean().getTrkseg().clear();
			// // QLog.getLogger().d(dTAG, "  track is"+track.toString());

			// }

		} catch (NumberFormatException ne) {
			Utils.logStackTrace(ne, TAG);
			showNotes("出错了");
			return;
		}
		/*
		 * catch (IOException localIOException){
		 * Utils.logStackTrace(localIOException, TAG); }
		 */
		catch (java.lang.IndexOutOfBoundsException IndexException) {
			Utils.logStackTrace(IndexException, TAG);
		} catch (Exception er) {
			Utils.logStackTrace(er, TAG);
		}

		requestUserFromWeb(userId);

	}

	void processUserJsonArray(JSONArray jsonArrary) {
		tmpData = new ArrayList<Map<String, String>>();
		JSONObject jo = null;
		User_bean ab;

		if (jsonArrary != null)
			for (int i = 0; i < jsonArrary.length(); i++) {
				try {
					jo = jsonArrary.getJSONObject(i);
					if (jo == null)
						continue;
					QLog.getLogger().d(dTAG, "jsonarray:--> " + jo.toString());
					ab = (User_bean) Utils.getGsonObject(jo.toString(),
							User_bean.class);

				} catch (JsonSyntaxException je) {
					Utils.logStackTrace(je, TAG);
					continue;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					Utils.logStackTrace(e, TAG);
					continue;
				}

				if (ab != null) {
					// tr= new Track(tb);
					Map<String, String> t = new HashMap<String, String>();
					t.put("name", Utils.getShortString(ab.getUserName(), 50) /*
																			 * .
																			 * getAccount
																			 * (
																			 * )
																			 */);

					t.put("id", String.valueOf(ab.getId()));
					// t.put("distance",String.valueOf(Utils.getFormatedDistance(ab.getDistance())));
					t.put("distance",
							String.format("%.1f", ab.getDistance() / 1000));
					t.put("calorie", String.format("%.0f", ab.getCalorie()));
					t.put("geo",
							String.format("%s %s", ab.getGeo().getCityName(),
									ab.getGeo().getDistrictName()).replace(
									"null", ""));

					String strUrls = Utils.getUserAlbum(ab);

					/*
					 * if(isShowPic){
					 * 
					 * strUrls=ab.getQqAbulmUrl(); }
					 */
					t.put("urls", strUrls);

					String d = String.format("%.0f", Utils.getDistanceFromXtoY(ab.getLat(), ab.getLon(), QiYouConstant.PV_LAST_LAT, QiYouConstant.PV_LAST_LON)/1000);
					String dist = ab.getLat() > 0 && QiYouConstant.PV_LAST_LAT > 0 ? d /*Utils.getDistanceRange(0,ab.getLat(), ab.getLon())*/ : "--" ;
				    t.put("distrange",dist ) ;
				    
//					t.put("distrange",
//							ab.getLat() > 0 && QiYouConstant.PV_LAST_LAT > 0 ? String
//									.format("%.1f", Utils.getDistanceFromXtoY(
//											ab.getLat(), ab.getLon(),
//											QiYouConstant.PV_LAST_LAT,
//											QiYouConstant.PV_LAST_LON) / 1000)
//									: "--");

					tmpData.add(t);
				}

			}

		userData = getListData(userData, tmpData);

		showNoRecText(userData.size() == 0);

		showUserData();

		// QLog.getLogger().e(dTAG,
		// String.format("pageNo is%s, actual pageno is %s ",pageNo,userData.size()/pageSize));

	}

	// QSimpleAdapter lvAdapter;

	int currentUserRow = 0;

	protected void showUserData() {
		// this.btn_pagedown.setEnabled(!isMemberLastPage);
		// this.btn_pageup.setEnabled(!isMemberFirstPage);

		lvAdapter = new QSimpleAdapter(activity, userData,
				R.layout.user_list_detail, new String[] { "urls", "name", "id",
						"distance", "distrange", "calorie", "geo", "id" },
				new int[] { R.id.user_abulm, R.id.actList_name,
						R.id.actList_svrNo, R.id.actList_dist,
						R.id.actList_distrange, R.id.actList_calorie,
						R.id.actList_geo, R.id.lst_btnDelUser });

		// lvWeb.setAdapter(lvAdapter);
		// lvAdapter.setSelectItem(selectMemberItem);
		// lvWeb.setSelection(selectMemberItem);

		Activity_bean act = getCurrentAct();
		Group_bean group = getCurrentGroup();

		final boolean canDel = (act != null
				&& act.getSvrNumber() > 0
				&& (this.getUser().getId() == act.getSvrNumber() || this
						.isAdmin()) || group != null && group.getId() > 0
				&& (this.getUser().getId() == group.getId() || this.isAdmin()));

		// QLog.getLogger().d(dTAG,String.format("------------canDel %s  act is null?%s   group is null? %s",
		// canDel,act==null,group==null));

		final int visible = canDel ? View.VISIBLE : View.GONE;

		lvAdapter.setViewBinder(new ViewBinder() {
			@Override
			public boolean setViewValue(View view, Object data,
					String textRepresentation) {

				switch (view.getId()) {

				case R.id.user_abulm: {
					com.qiyou.mb.android.utils.image.QimageView imgv = (com.qiyou.mb.android.utils.image.QimageView) view;

					if (data == null)
						return false;
					// QLog.getLogger().d(dTAG,
					// " displaying available image of " + data.toString());

					IL.DisplayImage(data.toString(), imgv);

					return true;
				}
				case R.id.lst_btnDelUser: {
					view.setVisibility(visible);

					if (canDel && data != null) {
						final int userId = Integer.parseInt(data.toString());
						Button btn = (Button) view;
						btn.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {

								/*
								 * AlertDialog.Builder builder = new
								 * Builder(activity);
								 * builder.setMessage("是否踢出该用户？");
								 * builder.setTitle("提示");
								 * builder.setCancelable(false);
								 * builder.setPositiveButton("确认", new
								 * android.content
								 * .DialogInterface.OnClickListener() {
								 * 
								 * @Override public void onClick(DialogInterface
								 * dialog, int which) { dialog.dismiss();
								 * removeUser(userId); } });
								 * builder.setNegativeButton("取消", new
								 * android.content
								 * .DialogInterface.OnClickListener() {
								 * 
								 * @Override public void onClick(DialogInterface
								 * dialog, int which) { dialog.dismiss();
								 * 
								 * } }); builder.create().show();
								 */

								removeUser(userId);
							}
						});
					}

					return true;
				}
				}

				return false;
			}
		});

		bindListView(lvAdapter, lvWeb, selectMemberItem, isMemberLastPage);
	}

	// ---------------------------------------------------------member query
	// end----------------------------------------------

	// ----------------group query begin----------------

	RequestParams buildGroupQueryParames() {
		RequestParams params = buildBasicParames(pageNo, -1);

		return params;

	}

	void doGroupQuery() {
		Utils.hideSoftKeyboard(activity);
		// noRec.setVisibility(View.GONE);
		isGroupQuery = true;

		if (this.firstLoad && !TextUtils.isEmpty(lastGrpQueryPara)) {
			return;
		}
		RequestParams param = buildGroupQueryParames();
		if (param != null
				&& !lastGrpQueryPara.equalsIgnoreCase(param.toString())) {

			// QLog.getLogger().d(dTAG, lastGrpQueryPara);
			// QLog.getLogger().d(dTAG, param.toString());

			getJsonWs(param, RestMethods.GRP_G_LIST/* "mb/group/list" */);
			lastGrpQueryPara = param.toString();
			selectGroupItem = -1;

		}

	}

	@Override
	void processGrpJsonArray(JSONArray jsonArrary) {

		tmpData = new ArrayList<Map<String, String>>();
		JSONObject jo = null;
		Group_bean ab;
		GEOaddress startgeo;
		if (jsonArrary != null)
			for (int i = 0; i < jsonArrary.length(); i++) {
				try {
					jo = jsonArrary.getJSONObject(i);
					if (jo == null)
						continue;
					// QLog.getLogger().d(dTAG, "jsonarray:--> "
					// +jo.toString());
					ab = (Group_bean) Utils.getGsonObject(jo.toString(),
							Group_bean.class);

				} catch (JsonSyntaxException je) {
					Utils.logStackTrace(je, TAG);
					continue;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					Utils.logStackTrace(e, TAG);
					continue;
				}

				if (ab != null) {
					// tr= new Track(tb);
					Map<String, String> t = new HashMap<String, String>();

					startgeo = new GEOaddress(ab.getGeo());

					t.put("name", ab.getName());
					t.put("svrNumber", ab.getId() + "");
					t.put("created",
							Utils.getFormatedTimeMonthDay(ab.getCreated()));
					t.put("description",
							Utils.getShortString(ab.getDesc(), STRLNG));
					t.put("startPlace",
							String.format("%s %s", ab.getPlace(),
									startgeo.toString(",")).replace("null", ""));
					t.put("shangquan", ab.getGeo().getComment());
//					t.put("distrg", String.format("队伍位置：%s", Utils
//							.getDistanceRange(/* ab.getDistrange() */0,
//									ab.getLat(), ab.getLon()))); 
					
					String dist = ab.getLat() > 0 && QiYouConstant.PV_LAST_LAT > 0 ? String.format("队伍位置：%s", Utils.getDistanceRange(0,ab.getLat(), ab.getLon())) : "--" ;  
				    t.put("distrg",dist ) ;

					t.put("userCnt", String.valueOf(ab.getUserCnt()));

					// t.put("timeLeft", "当前距活动开始剩余时间：" + getTimeLeft(ab));
					t.put("lastupdated", ab.getLastupdated() + "");
					/*
					 * String staticMapUrl
					 * =isShowPic?Utils.getBaiduStaticMapUrl(tr):""; // String
					 * staticMapUrl
					 * =Utils.getBaiduStaticUrlFromServer(tb.getSvrNumber()); //
					 * QLog.getLogger().d(dTAG,
					 * " static map url is: "+staticMapUrl); //
					 * QLog.getLogger().i(dTAG,
					 * " static map url is: "+staticMapUrl); t.put("staticmap",
					 * staticMapUrl );
					 */
					t.put("userName", ab.getUserName());
					// t.put("lastupdated", String.valueOf(ab.getLastdbTime())
					// );
					// t.put("cloud", "云：" );
					// QLog.getLogger().d(dTAG, "svrNumber:--> " + ab.getId());
					// // QLog.getLogger().d(dTAG, "lastupdated:--> " +
					// String.valueOf(ab.getLastdbTime()));

					t.put("type", String.valueOf(ab.getType()));

					t.put("dist",
							String.format("%.1f", ab.getDistance() / 1000));
					// t.put("avs", String.valueOf(ab.getAvSpeed()));

					t.put("rateLevel", String.valueOf(ab.getLevel()));

					t.put("timelong", String.format("%.1f",
							ab.getSportTime() / 1000 / 3600.0) /*
																 * Utils.
																 * getTimeCnt4Read
																 * (
																 * ab.getSportTime
																 * (), false)
																 */);
					// String[] urls=tr.getWebPicList(4, true);
					t.put("userCnt", String.valueOf(ab.getUserCnt()));
					String strUrls = "";
					if (isShowPic) {
						/*
						 * t.put("staticmap", ab.getStaticMapUrl() );
						 * 
						 * if(tb.getThumbUrls()!=null) for(String
						 * url:tb.getThumbUrls()){ // QLog.getLogger().d(dTAG,
						 * " url is" +url);
						 * strUrls+=QiYouConstant.BASE_MD_URL+url
						 * +QiYouConstant.SPLITOR; }
						 */
					}
					t.put("urls", strUrls);
					tmpData.add(t);
				}

			}
		grpData = getListData(grpData, tmpData);
		showNoRecText(grpData.size() == 0);

		showGrpData();

		// QLog.getLogger().e(dTAG,
		// String.format("pageNo is%s, actual pageno is %s ",
		// pageNo,grpData.size()/pageSize));

	}

	// QSimpleAdapter lvAdapter;

	int currentGrpRow = 0;

	protected void showGrpData() {
		// this.btn_pagedown.setEnabled(!isGrpLastPage);
		// this.btn_pageup.setEnabled(!isGrpFirstPage);

		lvAdapter = new QSimpleAdapter(activity, grpData,
				R.layout.group_list_detail, new String[] { "name", "svrNumber",
						"startTime", "startPlace", "shangquan", "description",
						"dist",

						"rateLevel", "timelong", "distrg", "userCnt",
						"userName" }, new int[] { R.id.actList_name,
						R.id.actList_svrNo, R.id.actList_starttime,
						R.id.actList_startplace, R.id.actList_shangquan,
						R.id.actList_desc, R.id.actList_dist,

						R.id.actList_level, R.id.actList_sportTime,
						R.id.actList_distRange, R.id.actList_memberCnt,
						R.id.actList_owner });

		// lvWeb.setAdapter(lvAdapter);
		// lvAdapter.setSelectItem(selectGroupItem);
		// lvWeb.setSelection(selectGroupItem);
		// QLog.getLogger().d(dTAG, "------ isGrpLastPage  .. " +
		// isGrpLastPage);

		bindListView(lvAdapter, lvWeb, selectGroupItem, isGrpLastPage);

	}

	/*
	 * int actSvrNumber; int actType; long actLastupdated;
	 */

	void showGroupDetail(int position) {

		int grpSvrNumber = 0;

		if (lvAdapter == null || lvAdapter.getCount() <= position) {
			// QLog.getLogger().e(dTAG,
			// "wrong group position clicked,reurn....");
			return;
		}
		try {
			this.lvAdapter.setSelectItem(position);
			this.lvAdapter.notifyDataSetInvalidated();
			// this.lvWeb.setSelection(position);
			HashMap<String, String> localHashMap = (HashMap<String, String>) this.lvAdapter
					.getItem(position);
			grpSvrNumber = Integer.parseInt(localHashMap.get("svrNumber"));
			/*
			 * if(localHashMap.get("type")!=null &&
			 * !localHashMap.get("type").equalsIgnoreCase("null")){ try{
			 * this.actType = Integer.parseInt(localHashMap.get("type")) ;
			 * }catch(NumberFormatException ne ){ Utils.logStackTrace(ne, TAG);
			 * } }
			 */
			// this.grpLastupdated =
			// Long.parseLong(localHashMap.get("lastupdated")) ;
			// }catch(NumberFormatException ne ){
			// Utils.logStackTrace(ne, TAG);
			// showNotes("出错了");
			// return;
			// }
			// QLog.getLogger().d("com.qiyou", TAG +
			// " get selected grpSvrNumber:" + grpSvrNumber);

		} catch (NumberFormatException ne) {
			Utils.logStackTrace(ne, TAG);
			showNotes("出错了");
			return;
		}

		catch (java.lang.IndexOutOfBoundsException IndexException) {
			Utils.logStackTrace(IndexException, TAG);
		} catch (Exception er) {
			Utils.logStackTrace(er, TAG);
		}

		requestGroupFromWeb(grpSvrNumber);
	}

	void requestGroupFromWeb(int svrNo) {
		RequestParams params = new RequestParams();
		params.add("id", String.valueOf(svrNo));
		// QLog.getLogger().d(dTAG, TAG+" web query params: "+params);
		getJsonWs(params, RestMethods.GRP_G_FIND_BY_ID/* "mb/activity/" */);
		// long l1 = System.currentTimeMillis();
		// // QLog.getLogger().d("com.qiyou", TAG +
		// " start Click item to show track detail, time is:" + l1);
		// getJsonWs(null, "mb/track/" + this.svrNumber);
		// /long l2 = System.currentTimeMillis() - l1;
		// // QLog.getLogger().d("com.qiyou", TAG + " get data from web cost:" +
		// l2);
	}

	// @Override
	// void showGroup(Group_bean group) {
	// activity.showGroup(group);
	// }

	// /------------------------------------------group query
	// end-------------------------------

	// begin BBS List -------------------------------BBS
	// begin--------------------------------------

	// boolean isNoteQuery ;
	String lastNoteQueryPara;
	// int pageNo;
	int noteId;
	int svrNo;
	List<Map<String, String>> bbsData;
	Button btnNew, btnRefresh;

	void doBBSQuery() {
		Utils.hideSoftKeyboard(activity);

		// isNoteQuery=true;
		// lvWeb.setVisibility(View.VISIBLE);
		// lv.setVisibility(View.GONE);
		QLog.getLogger().d(dTAG, TAG + "------begin Note query--------- ");

		/*
		 * if( this.firstLoad&&!TextUtils.isEmpty(lastNoteQueryPara)){ return; }
		 */
		RequestParams param = buildNotesQueryParames();
		if (param != null) {

			QLog.getLogger().d(dTAG, lastNoteQueryPara);
			QLog.getLogger().d(dTAG, param.toString());

			getJsonWs(param, RestMethods.NOTE_G_LIST /* "mb/user/actusers" */);

			selectedBBSItem = -1;

		}

	}

	RequestParams buildNotesQueryParames() {
		RequestParams params = buildBasicParames(pageNo, -1);
		params.add("cate1", String.valueOf(this.BBScate));
		params.add("cate2", String.valueOf(this.BBSSubcate));

		if (BBScate == BBSCate.USER.toInt()) {
			params.put("owner", -1);
		}

		return params;

	}

	void showNoteDetail(int position) {
		try {
			this.lvAdapter.setSelectItem(position);
			this.lvAdapter.notifyDataSetInvalidated();
			// this.lvWeb.setSelection(position);
			HashMap<String, String> localHashMap = (HashMap<String, String>) this.lvAdapter
					.getItem(position);
			noteId = Integer.parseInt(localHashMap.get("id"));

			QLog.getLogger().d("com.qiyou",
					TAG + " get selected noteId:" + this.noteId);

		} catch (NumberFormatException ne) {
			Utils.logStackTrace(ne, TAG);
			showNotes("出错了");
			return;
		} catch (java.lang.IndexOutOfBoundsException IndexException) {
			Utils.logStackTrace(IndexException, TAG);
		} catch (Exception er) {
			Utils.logStackTrace(er, TAG);
		}

		requestNoteFromWeb(noteId);

	}

	void requestNoteFromWeb(int noteId) {
		if (noteId <= 0)
			return;
		RequestParams params = new RequestParams();
		params.add("id", String.valueOf(noteId));
		getJsonWs(params, RestMethods.NOTE_G_FIND_BY_ID);
	}

	@Override
	void processNotesJsonArray(JSONArray jsonArrary) {
		ArrayList<Map<String, String>> tmpData = new ArrayList<Map<String, String>>();
		JSONObject jo = null;
		Note ab;

		if (jsonArrary != null)
			for (int i = 0; i < jsonArrary.length(); i++) {
				try {
					jo = jsonArrary.getJSONObject(i);
					if (jo == null)
						continue;
					// QLog.getLogger().d(dTAG, "jsonarray:--> "
					// +jo.toString());
					ab = (Note) Utils.getGsonObject(jo.toString(), Note.class);

				} catch (JsonSyntaxException je) {
					Utils.logStackTrace(je, TAG);
					continue;
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					Utils.logStackTrace(e, TAG);
					continue;
				}

				if (ab != null) {
					Map<String, String> t = new HashMap<String, String>();
					t.put("title", ab.getTitle()/* .getAccount() */);
					t.put("id", String.valueOf(ab.getId()));
					t.put("body", ab.getBody());
					t.put("username", ab.getUserName()/*
													 * ab.getOwner()!=null?ab.
													 * getOwner
													 * ().getUserName():""
													 */);
					t.put("created", Utils.getFormatedTime(ab.getCreated()));
					t.put("replycnt", ab.getReplyCnt() + "");
					t.put("lastreply",
							ab.getLastupdated() > ab.getCreated() ? ab
									.getLastReplyer() : "");

					BBSCate cate = BBSCate.values()[ab.getCategory()];
					String cateName = ab.getCategory() == this.BBScate
							&& ab.getSubCate() == this.BBSSubcate ? "" : "["
							+ cate.toCHString() + "]";
					String subCateName = TextUtils.isEmpty(cateName) ? ""
							: TextUtils.isEmpty(ab.getSubCateName()) ? "" : "["
									+ ab.getSubCateName() + "]";
					t.put("cateName", cateName);
					t.put("subCatename", subCateName);
					if (TextUtils.isEmpty(cateName)
							&& TextUtils.isEmpty(subCateName)) {
						t.put("cates", null);
					}
					t.put("cateOwnerId", ab.getCateOwnerId() + "");
					t.put("album", Utils.getUserAlbum(ab.getUserAlbum()));
					// int priorityType = ab.getMainPriority() > 0 ? 0 :
					// ab.getCatePriority()>0 ? 1 : ab.getPriority() > 0?2 : -1;
					int priorityImgsrc = ab.getMainPriority() > 0 ? R.drawable.icon_maintop
							: ab.getCatePriority() > 0 ? R.drawable.icon_catetop
									: ab.getPriority() > 0 ? R.drawable.icon_subcatetop
											: -1;
					if (priorityImgsrc > 0) {
						t.put("priorityImgsrc", priorityImgsrc + "");
					}

					tmpData.add(t);
				}

			}

		bbsData = getListData(bbsData, tmpData);

		showNoRecText(bbsData.size() == 0);

		showBBSData();

		QLog.getLogger().e(
				dTAG,
				String.format("pageNo is%s, actual pageno is %s ", pageNo,
						bbsData.size() / pageSize));

	}

	// QSimpleAdapter notesSimpleAdapter;

	protected void showBBSData() {

		lvAdapter = new QSimpleAdapter(activity, bbsData,
				R.layout.notes_list_detail, new String[] { "title", "body",
						"id", "username", "created", "replycnt", "lastreply"

						, "cateName", "subCatename", "priorityImgsrc", "album"
				// ,"cates"
				}, new int[] { R.id.list_note_name, R.id.list_note_body,
						R.id.list_note_id, R.id.list_note_username,
						R.id.list_note_created, R.id.list_note_reply_cnt,
						R.id.list_note_reply_user

						, R.id.list_note_cate, R.id.list_note_subcate,
						R.id.list_note_imgCateTop, R.id.list_note_imgUserAbulm
				// ,R.id.list_cate
				});

		lvAdapter.setViewBinder(new ViewBinder() {
			@Override
			public boolean setViewValue(View view, Object data,
					String textRepresentation) {

				switch (view.getId()) {

				case R.id.list_note_imgCateTop: {
					com.qiyou.mb.android.utils.image.QimageView imgv = (com.qiyou.mb.android.utils.image.QimageView) view;

					if (data == null) {
						// imgv.setVisibility(View.GONE);
						return false;
					}
					imgv.setVisibility(View.VISIBLE);
					// QLog.getLogger().d(dTAG,
					// " displaying available image of " + data.toString());
					imgv.setImageResource(Integer.valueOf(data.toString()));
					// IL.DisplayImage( data.toString(),imgv);

					return true;
				}
				case R.id.list_note_imgUserAbulm: {
					com.qiyou.mb.android.utils.image.QroundimageView imgv = (com.qiyou.mb.android.utils.image.QroundimageView) view;

					if (data == null) {

						return false;
					}
					QLog.getLogger()
							.d(dTAG,
									" displaying available image of "
											+ data.toString());
					IL.DisplayImage(data.toString(), imgv);

					return true;
				}
				case R.id.list_note_subcate: {

					view.setVisibility(View.VISIBLE);
					if (data != null && TextUtils.isEmpty(data.toString())) {

						view.setVisibility(View.GONE);
						return true;
					}

					return false;
				}
				case R.id.list_note_cate: {

					view.setVisibility(View.VISIBLE);
					if (data != null && TextUtils.isEmpty(data.toString())) {

						view.setVisibility(View.GONE);
						return true;
					}

					return false;
				}
				// case R.id.list_cate:{
				//
				//
				// if(data==null ){
				//
				// view.setVisibility(View.GONE);
				//
				// }
				//
				//
				// return true;
				// }

				}

				return false;
			}
		});

		bindListView(lvAdapter, lvWeb, selectedBBSItem, isBBSLastPage);

		lvWeb.setDividerHeight(2);

	}

	// void initialNotesQuery(){
	// pageNo=1;
	// doBBSQuery();
	// }

	// /////------------ BBS end

	private WebQueryCate getSelectedCate() {
		WebQueryCate wq = WebQueryCate.LATEST;
		if (spWebInputType == null) {
			return wq;
		}
		int selected = spWebInputType.getSelectedItemPosition();
		String selectedItem = spAdapterWeb.getItem(selected).toString();
		int cateIndex = totalList.indexOf(selectedItem);
		if (cateIndex == -1) {
			if (BBSCity.equalsIgnoreCase(selectedItem)) {
				wq = WebQueryCate.CITY;
			}
		} else {
			// wq = WebQueryCate.valueOf(cateIndex);
			wq = WebQueryCate.values()[cateIndex];
		}

		return wq;
	}

	RequestParams buildBasicParames(int pageNo, int type) {
		RequestParams params = new RequestParams();

		final int GEO_CITY_TYPE = 2;
		String userName = null;
		String svrNo = null;
		String cityName = null;
		String keyName = null;
		/*
		 * if(edUserName!=null){ userName=edUserName.getText().toString();
		 * svrNo= edSvrNo.getText().toString();
		 * cityName=webCity.getText().toString(); }
		 */
		isShowMyNearbyOnly = false;
		isShowMytrackOnly = false;

		if (spWebInputType != null) {

			this.BBSSubcate = 0;
			this.BBSsubCateName = "";
			this.BBScate = BBSCate.NORMAL.toInt();

			// int selected = spWebInputType.getSelectedItemPosition();
			// String selectedItem = spAdapterWeb.getItem(selected).toString();
			WebQueryCate wq = getSelectedCate();
			/*
			 * WebQueryCate.LATEST;
			 * 
			 * int cateIndex = totalList.indexOf(selectedItem);
			 * 
			 * if (cateIndex == -1){ if(BBSCity.equalsIgnoreCase(selectedItem)){
			 * wq = WebQueryCate.CITY; } }else { // wq =
			 * WebQueryCate.valueOf(cateIndex); wq =
			 * WebQueryCate.values()[cateIndex]; }
			 */

			switch (wq) {
			case LATEST:

				break;
			case MYNEARBY:
				isShowMyNearbyOnly = true;
				break;
			case GEO:
				cityName = txt_webinput.getText().toString();
				if (TextUtils.isEmpty(cityName)) {
					cityName = QiYouConstant.PV_LAST_CITY;
				}
				break;
			case KEYWORD:
				keyName = txt_webinput.getText().toString();
				if (TextUtils.isEmpty(keyName)) {

					return params;
				}
				break;
			case MINE:
				isShowMytrackOnly = true;
				break;
			case USER:
				userName = txt_webinput.getText().toString();
				break;
			case SVRNO:
				svrNo = txt_webinput.getText().toString();
				break;
			case BIKE:
				type = TrackType.BIKE.toInt();
				break;
			case GPX:
				type = TrackType.GPX.toInt();
				break;
			case HIKE:
				type = TrackType.HIKE.toInt();
				break;
			case MOTOR:
				type = TrackType.MOTOR.toInt();
				break;
			case SCORE:
				break;

			// below is for bbs
			case QXTD:
				this.BBScate = BBSCate.QXTD.toInt();
				break;
			case PYJL:
				this.BBScate = BBSCate.PYJL.toInt();
				break;
			case TBDS:
				this.BBScate = BBSCate.TBDS.toInt();
				break;
			case ACTIVITY:
				this.BBScate = BBSCate.ACT.toInt();
				break;
			case GROUP:
				this.BBScate = BBSCate.GROUP.toInt();
				break;
			case LEARNING:
				this.BBScate = BBSCate.LEARNING.toInt();
				break;
			case QANDA:
				this.BBScate = BBSCate.QANDA.toInt();
				break;
			case BIKECARE:
				this.BBScate = BBSCate.BIKECARE.toInt();
				break;
			case CITY:
				this.BBScate = BBSCate.GEO.toInt();
				this.BBSSubcate = activity.app.user.getUserbean().getGeo()
						.getCity();
				this.BBSsubCateName = activity.app.user.getUserbean().getGeo()
						.getCityName();

				break;
			}
		}

		if (!TextUtils.isEmpty(svrNo)) {
			params.add("svrNo", svrNo);
			return params;
		}

		params.add("page", String.valueOf(pageNo));
		params.add("pagesize", String.valueOf(pageSize));

		params.add("type", String.valueOf(type));

		if (isShowMytrackOnly) {
			// params.add("isMyOnly", String.valueOf(isShowMytrackOnly));
			params.add("ownerId",
					String.valueOf(activity.app.user.getUserbean().getId()));
		} else if (isShowMyNearbyOnly) {
			params.add("isNearby", String.valueOf(this.isShowMyNearbyOnly));
			params.add("lat", String.valueOf(QiYouConstant.PV_LAST_LAT));
			params.add("lon", String.valueOf(QiYouConstant.PV_LAST_LON));
			params.add("dist", String.valueOf(50));
		}

		if (!TextUtils.isEmpty(keyName)) {
			try {
				params.add("keyName", URLEncoder.encode(keyName, "UTF-8"));
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				Utils.logStackTrace(e, dTAG);
			}

		}

		if (!TextUtils.isEmpty(cityName)) {
			try {
				params.add("geoName", URLEncoder.encode(cityName, "UTF-8"));
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				Utils.logStackTrace(e, dTAG);
			}
			params.add("geoType", String.valueOf(GEO_CITY_TYPE));
		}
		if (!TextUtils.isEmpty(userName)) {

			try {
				params.add("userName", URLEncoder.encode(userName, "UTF-8"));
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				Utils.logStackTrace(e, dTAG);
			}
		}

		// QLog.getLogger().d(dTAG, TAG+" web query params: "+params);

		return params;
	}

	@Override
	protected void onMyTabChanged(String tabId) {
		super.onMyTabChanged(tabId);
		/*
		 * if(tabhost==null)return; initialTabhostStyle(tabhost);
		 * setSelectedTabhostStyle(tabhost); currentTab=
		 * tabhost.getCurrentTab();
		 */
		lastSelectedCateId = -1;
		isSwitchWebInputOnly = true;
		getQueryCate();
		processTabQuery();

		// isLastPage=false;
	}

	void processTabQuery() {
		setNote();
		isLoadingMore = false;
		pageNo = 1;
		if (progressDialog != null)
			progressDialog.dismiss();
		// noRec.setVisibility(View.GONE);
		QLog.getLogger().d(
				dTAG,
				"  tab changed....to... " + currentTab + ", isLoadingMore? "
						+ isLoadingMore);
		switchTabOptions(currentTab);
		// lvWeb.setVisibility(View.GONE);
		// this.lvWeb.setVisibility(View.GONE);
		// lvWeb.setVisibility(View.GONE);
		// lvWeb.setVisibility(View.GONE);
		// lvWeb.setVisibility(View.GONE);
		if (!validInput()) {
			return;
		}
		if (imgWebPlus != null) {
			imgWebPlus.setVisibility(View.GONE);
		}
		canclick = true;
		/*
		 * if(currentTab==0){ this.lv.setVisibility(View.VISIBLE); doQuery();
		 * }else if(isByCatesQuery){ this.lv.setVisibility(View.VISIBLE);
		 * doCatesQuery(); // }else if(isInactiveQuery){ // doInactiveQuery();
		 * }else if(isRouteQuery){ this.lv.setVisibility(View.VISIBLE);
		 * doRouteQuery(); }else
		 */
		showNoRecText(false);

		if (firstLoad) {
			WebQueryCate wq = getSelectedCate();
			if (wq == WebQueryCate.SVRNO) {
				return;
			}
		}

		if (isWebTrackQuery) {
			// ll_webinput.setVisibility(View.VISIBLE);
			// lvWeb.setVisibility(View.VISIBLE);
			// QLog.getLogger().d(dTAG, "trackData is Null? " +
			// (trackData==null));

			if (activity.isNeedFresh) {
				activity.isNeedFresh = false;
				doWebTrackQuery();
				this.isSwitchWebInputOnly = false;
				return;
			}

			if (trackData == null) {

				doWebTrackQuery();
			} else
				showWebTrackListData(trackData);

			if (trackData != null)
				showNoRecText(trackData.size() == 0);

		} else if (isActivityQuery) {
			if (imgWebPlus != null) {
				imgWebPlus.setVisibility(View.VISIBLE);
			}
			// ll_webinput.setVisibility(View.VISIBLE);
			// lvWeb.setVisibility(View.VISIBLE);
			// QLog.getLogger().d(dTAG, "actData is Null? " + (actData==null));
			if (actData == null)
				// doActQuery();
				doActQuery();
			else
				showActData();

			if (actData != null)
				showNoRecText(actData.size() == 0);

		} else if (isGroupQuery) {
			if (imgWebPlus != null) {
				imgWebPlus.setVisibility(View.VISIBLE);
			}
			// lvWeb.setVisibility(View.VISIBLE);
			// QLog.getLogger().d(dTAG, "grpData is Null? " + (grpData==null));
			if (grpData == null)
				doGroupQuery();
			else
				showGrpData();

			if (grpData != null)
				showNoRecText(grpData.size() == 0);

		} else if (isMemberQuery) {
			// lvWeb.setVisibility(View.VISIBLE);
			if (userData == null)
				doUserQuery();
			else
				showUserData();
			if (userData != null)
				showNoRecText(userData.size() == 0);

		} else if (isBBSQuery) {
			// lvWeb.setVisibility(View.VISIBLE);
			// lvWeb.setVisibility(View.VISIBLE);
			if (imgWebPlus != null) {
				imgWebPlus.setVisibility(View.VISIBLE);
			}
			if (activity.isNeedFresh) {
				activity.isNeedFresh = false;
				doBBSQuery();
				this.isSwitchWebInputOnly = false;
				return;
			}

			if (bbsData == null)
				doBBSQuery();
			else
				showBBSData();

		}

		// lvWeb.setVisibility(View.VISIBLE);
	}

	void switchTabOptions(int queryType) {

		if (lvWeb == null) {
			return;
		}
		lvWeb.setVisibility(View.GONE);

		isBBSQuery = queryType == 0;
		isWebTrackQuery = queryType == 1;
		isActivityQuery = queryType == 2;
		isGroupQuery = queryType == 3;
		isMemberQuery = queryType == 4;

		if (spWebInputType == null)
			return;

		// setSpSelection();

		// tmp.get(Integer.valueOf( spWebInputType.getSelectedItemPosition()))
		// this.txt_webinput.setText( tmp.get(Integer.valueOf(
		// spWebInputType.getSelectedItemPosition())) );
		this.chk_web_pic.setVisibility(isWebTrackQuery ? View.VISIBLE
				: View.GONE);
	}

	Activity_bean getCurrentAct() {
		return null;
	}

	Group_bean getCurrentGroup() {
		return null;
	}

	void setSpSelection() {
		// super.firstLoad = true; //tab changes,spWebInput items changes, wont'
		// fire the doQuery() again
		Object a = activity.app.tabSpIndex.get(String.valueOf(currentTab)); // java.lang.Double
																			// cannot
																			// be
																			// cast
																			// to
																			// java.lang.Integer
		Double id = Double.valueOf(a.toString());
		int cacheId = id.intValue();// (int)
									// activity.app.tabSpIndex.get(String.valueOf(currentTab))
									// ;
		lastSelectedCateId = cacheId;
		if (cacheId != spWebInputType.getSelectedItemPosition()) {
			// isSwitchWebInputOnly = true; // whe back from oth222er fragment,
			// no query
			spWebInputType.setSelection(cacheId);

		}

		if (tabSpIndexValue == null) {
			tabSpIndexValue = new HashMap<Integer, Map<Integer, String>>();

		}

		this.txt_webinput.setVisibility(View.GONE);
		this.btn_webquery.setVisibility(View.GONE);
		Map<Integer, String> tmp = tabSpIndexValue.get(Integer
				.valueOf(currentTab));
		if (tmp != null) {

			String cachedTxt = tmp.get(Integer.valueOf(spWebInputType
					.getSelectedItemPosition()));
			this.txt_webinput.setText(cachedTxt);
			this.txt_webinput.setVisibility( cachedTxt == null ? View.GONE : View.VISIBLE);
			this.btn_webquery.setVisibility(txt_webinput.getVisibility());

		}
		setNote();
		// isSwitchWebInputOnly = true;
		// webSpinnerSelected(this.activity.app.tabSpIndex.get(Integer.valueOf(currentTab)));
	}

	/**
	 * reomve user from the group or activity ... etc member list the method
	 * need to be overrided in group or activity ...fragment.
	 * 
	 * @param userId
	 *            ,user to remove
	 */
	void removeUser(int userId) {

	}

	@Override
	public boolean isShowBottomTabs() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void setTabOnFiling() {

		maxTabIndex = 4;

	}

	@Override
	protected void setSelectedTab() {
		if (tabhost != null) { // && tabhost.getCurrentTab()!=currentTab){
			if (tabhost.getCurrentTab() != currentTab) { // back from navigation
				tabhost.setCurrentTab(currentTab);
			} else if (currentTab == 0) {// on first load
				this.processTabQuery();
			}
		}
	}

	@Override
	public void onResume() {
		// activity.app.currentActiveFragment =TAG;
		super.onResume();
		// activity.updateActionBarTitle( R.string.frg_trackWeb );
		// //
		// QLog.getLogger().e(dTAG,TAG+" app.currentActiveFragment of trackList: "+TAG);
		// if(tabhost!= null && tabhost.getCurrentTab() != currentTab){
		// processTabQuery();
		// }

	}

	@Override
	public void onPause() {
		super.onPause();
		if (progressDialog != null)
			progressDialog.dismiss();
	}

	@Override
	void setNote() {
		
		if(txtNote== null){
			return;
		}
		
		txtNote.setVisibility(View.VISIBLE);
		String noteTxt = "";

		WebQueryCate wq = getSelectedCate();
		 TextView tv = (TextView) tabhost.getTabWidget().getChildAt(currentTab).findViewById(android.R.id.title);
		 String tabTxt =  tv.getText().toString();
		 if (currentTab == 0 ){ 
			if (wq == WebQueryCate.LATEST){
				noteTxt =  BBSCate.NORMAL.toCHString() + ",最新"  + tabTxt;//+BBSCate.NORMAL.toCHString(); 
			}else if(wq==WebQueryCate.MINE) {
				noteTxt =  "我发表的"  + tabTxt;//+ tabhost.getCurrentTabTag();
			}else {
			 noteTxt = wq.toCHString(); 
			}
		 }else if (currentTab == 4 &&  wq == WebQueryCate.LATEST){
			 noteTxt = "驴友排行榜"; //  + tabTxt;
		 }
		 else {
			 noteTxt = wq.toCHString()  + tabTxt;// + tabhost.getCurrentTabTag();
		 }
//		 else if(isWebTrackQuery){
//			 noteTxt =     super.BBSsubCateName   + " 相关路书";
//		 }else if(isMemberQuery){
//			 noteTxt =   super.BBSsubCateName  + "成员";
//		 }else if(isShareQuery){
//			 noteTxt =  super.BBSsubCateName  + "的运动分享";
//		 }else if(isLiveQuery){
//			 noteTxt =   super.BBSsubCateName  + "位置直播";
//		 }else if(isActivityQuery){
//			 noteTxt =   super.BBSsubCateName  + "的相关活动";
//		 }else if(super.isGroupQuery){
//			 noteTxt =   super.BBSsubCateName  + "的相关队伍";
//		 } 
		
		
	    txtNote.setText(noteTxt);
		 

	}
	@Override
	void hideNotes(){
		   
	 }
	
}
