【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】android 開(kāi)源項(xiàng)目(城市定位)_第1頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】android 開(kāi)源項(xiàng)目(城市定位)_第2頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】android 開(kāi)源項(xiàng)目(城市定位)_第3頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】android 開(kāi)源項(xiàng)目(城市定位)_第4頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】android 開(kāi)源項(xiàng)目(城市定位)_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】android開(kāi)源項(xiàng)目(城市定位)

importjava.util.ArrayList;importorg.json.JSONArray;importorg.json.JSONException;importorg.json.JSONObject;importorg.lfg.Utils.MyVolley;importorg.lfg.Utils.StringRequestUTF;importorg.lfg.cityselect_activity.CityHomeActivity;importorg.lfg.widgets.ListViewForScrollView;importBaseAdapter.Contains;importandroid.annotation.SuppressLint;importandroid.content.Intent;importandroid.os.Bundle;importandroid.support.v4.app.Fragment;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.view.ViewGroup;importandroid.widget.BaseAdapter;importandroid.widget.Button;importandroid.widget.ImageButton;importandroid.widget.ImageView;importandroid.widget.ScrollView;importandroid.widget.TextView;importandroid.widget.Toast;importcom.android.volley.Request.Method;importcom.android.volley.RequestQueue;importcom.android.volley.Response.ErrorListener;importcom.android.volley.Response.Listener;importcom.android.volley.VolleyError;importcom.android.volley.toolbox.StringRequest;importcom.example.nuomi.AllActivity;importcom.example.nuomi.R;importcom.handmark.pulltorefresh.library.MyScrollView;importcom.handmark.pulltorefresh.library.MyScrollView.OnScrollListener;importcom.handmark.pulltorefresh.library.PullToRefreshBase;importcom.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;importcom.handmark.pulltorefresh.library.PullToRefreshScrollView;importcom.nostra13.universalp_w_picpathloader.core.DisplayImageOptions;importcom.nostra13.universalp_w_picpathloader.core.ImageLoader;publicclasstodayFragmentextendsFragment

{ privateListViewForScrollViewmlistmnue; privatePullToRefreshScrollViewmScrollview; protectedImageLoaderp_w_picpathLoader=ImageLoader.getInstance(); privateArrayList<MenuList>

context=newArrayList<todayFragment.MenuList>(); privateStringstrUrl=Contains.strUrl; privateDisplayImageOptionsoptions; privatemlistmnueAdaptermAdapter; privateTextViewmTvall; privateImageButtonmBtnBackTop; privateButtonmLocationcity;

@Override

publicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer, BundlesavedInstanceState)

{ Viewlayout=inflater.inflate(R.layout.home,null);

InitUI(layout); Options(); InitScroll(layout); HttpConn(); returnlayout;

} /*

*

卻接受CityHomeActivity的消息

*/ @Override publicvoidonActivityResult(intrequestCode,intresultCode,Intentdata){ if(data!=null) { if(resultCode==1) { StringcityName=data.getStringExtra("city"); intend=cityName.indexOf("市"); mLocationcity.setText(cityName.substring(0,end)); } }else {

Toast.makeText(getActivity(),"親!定位失敗哦~~~",Toast.LENGTH_SHORT).show(); } super.onActivityResult(requestCode,resultCode,data); } privatevoidInitUI(Viewlayout){ mBtnBackTop=(ImageButton)layout.findViewById(R.id.img_backtop);

mBtnBackTop.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ ScrollViewscrollView=(ScrollView)mScrollview.findViewById(R.id.scrollview); scrollView.smoothScrollTo(0,0); } });

//

跳轉(zhuǎn)全部團(tuán)購(gòu)頁(yè)面

TextViewfind_more=(TextView)layout.findViewById(R.id.find_more);

find_more.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){

Intentintent=newIntent(getActivity(),AllActivity.class); startActivity(intent);

} });

//

定位城市事件

mLocationcity=(Button)layout.findViewById(R.id.btn_locationcity);

mLocationcity.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ Intentintent=newIntent(getActivity(),CityHomeActivity.class); startActivityForResult(intent,0); } });

}

@SuppressLint("NewApi") privatevoidHttpConn(){ Listener<String>listener=newListener<String>()

{ @Override publicvoidonResponse(Stringresponse)

{ try{ JSONObject

jsonObj=newJSONObject(response); JSONArrayjsonarr=jsonObj.getJSONArray("deals");

for(inti=0;i<jsonarr.length();i++)

{

JSONObjectjsonObject=jsonarr.getJSONObject(i); Stringname=jsonObject.getString("name"); Stringthumbnail=jsonObject.getString("thumbnail"); Stringsolds=jsonObject.getString("solds"); Stringprice=jsonObject.getString("price"); Stringvalue=jsonObject.getString("value"); Stringtitle=jsonObject.getString("title"); MenuListmenuList=newMenuList(name,thumbnail,solds,price,value,title); context.add(menuList); } }catch(JSONExceptione){ e.printStackTrace(); } mAdapter.notifyDataSetChanged(); } }; ErrorListenererrorListener=newErrorListener()

{ @Override publicvoidonErrorResponse(VolleyErrorerror)

{//

Toast.makeText(getActivity(),"網(wǎng)絡(luò)連接有問(wèn)題"+error,Toast.LENGTH_SHORT).show(); } }; volleyGet(strUrl,listener,errorListener); } // 下載文件(注意結(jié)合ListView數(shù)據(jù)設(shè)置始終是去設(shè)置ListView) privatevoidvolleyGet(Stringurl,Listener<String>listener, ErrorListenererrorListener) { RequestQueuequeue=MyVolley.getRequestQueue(); StringRequestrequest= newStringRequestUTF(Method.GET,url,listener,errorListener); queue.add(request); } //

圖片下載前、顯示 privatevoidOptions()

{ options=newDisplayImageOptions.Builder() .showImageOnLoading(R.drawable.about_logo) .showImageForEmptyUri(R.drawable.about_logo) .showImageOnFail(R.drawable.about_logo) .cacheInMemory(true) .cacheOnDisk(true) .considerExifParams(true)// .displayer(newRoundedBitmapDisplayer(8)) .build(); }

// 解決ScrollView滑動(dòng)的問(wèn)題 privatevoidInitScroll(Viewlayout){ mlistmnue=(ListViewForScrollView)layout.findViewById(R.id.listViewForScrollView1); mAdapter=newmlistmnueAdapter(); mlistmnue.setAdapter(mAdapter);// 使用ScrollView滑動(dòng)到最頂部

mScrollview=(PullToRefreshScrollView)layout.findViewById(R.id.scrollView1);

MyScrollViewscrollView=(MyScrollView)mScrollview.findViewById(R.id.scrollview);

scrollView.setOnScrollListener(newOnScrollListener(){ @Override publicvoidonScroll(intscrollY){ if(scrollY==0) { mBtnBackTop.setVisibility(View.INVISIBLE); } else { mBtnBackTop.setVisibility(View.VISIBLE); } } });

scrollView.smoothScrollTo(0,0);

mScrollview.setOnRefreshListener(newOnRefreshListener(){ @Override publicvoidonRefresh(PullToRefreshBaserefreshView){ newThread() { @Override publicvoidrun(){ try{ Thread.sleep(3000); }catch(InterruptedExceptione){

e.printStackTrace(); } getActivity().runOnUiThread(newRunnable(){ publicvoidrun(){ mScrollview.onRefreshComplete(); } }); } }.start(); } }); }

privateImageViewmbackTop;//

設(shè)置適配器 classmlistmnueAdapterextendsBaseAdapter { @Override publicViewgetView(intposition,ViewconvertView,ViewGroupparent)

{ ListInfolistInfo=null; Viewinflate=null; if(convertView==null) { listInfo=newListInfo(); inflate=getActivity().getLayoutInflater().inflate(R.layout.munulist,null); listInfo.LTiltle=(TextView)inflate.findViewById(R.id.Title); listInfo.LStore=(TextView)inflate.findViewById(R.id.Store); listInfo.LDesContext=(TextView)inflate.findViewById(R.id.DesContext); listInfo.LCurrprice=(TextView)inflate.findViewById(R.id.Currprice); listInfo.LOldprice=(TextView)inflate.findViewById(R.id.Oldprice); listInfo.LCount=(TextView)inflate.findViewById(R.id.Count); listInfo.mImageView=(ImageView)inflate.findViewById(R.id.p_w_picpath_advertes);

// 解決如何去實(shí)現(xiàn)點(diǎn)擊跳到頂部// mbackTop=(ImageView)inflate.findViewById(R.id.img_backtop);

inflate.setTag(listInfo); } else { inflate=convertView; listInfo=(ListInfo)inflate.getTag(); }// scrollView.smoothScrollTo(0,0); MenuListmenuList=context.get(position); listInfo.LTiltle.setText(menuL); Stringimg=menuList.thumbnail; p_w_picpathLoader.displayImage( img,

listInfo.mImageView,

options,

null); returninflate; } @Override publicintgetCount()

{ returncontext.size(); } @Override publicObjectgetItem(intpo

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論