资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

android开源项目(城市定位)

import java.util.ArrayList;

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了潼南免费建站欢迎大家使用!

import org.json.JSONArray;

import org.json.JSONException;

import org.json.JSONObject;

import org.lfg.Utils.MyVolley;

import org.lfg.Utils.StringRequestUTF;

import org.lfg.cityselect_activity.CityHomeActivity;

import org.lfg.widgets.ListViewForScrollView;

import BaseAdapter.Contains;

import android.annotation.SuppressLint;

import android.content.Intent;

import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.LayoutInflater;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.Button;

import android.widget.ImageButton;

import android.widget.ImageView;

import android.widget.ScrollView;

import android.widget.TextView;

import android.widget.Toast;

import com.android.volley.Request.Method;

import com.android.volley.RequestQueue;

import com.android.volley.Response.ErrorListener;

import com.android.volley.Response.Listener;

import com.android.volley.VolleyError;

import com.android.volley.toolbox.StringRequest;

import com.example.nuomi.AllActivity;

import com.example.nuomi.R;

import com.handmark.pulltorefresh.library.MyScrollView;

import com.handmark.pulltorefresh.library.MyScrollView.OnScrollListener;

import com.handmark.pulltorefresh.library.PullToRefreshBase;

import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;

import com.handmark.pulltorefresh.library.PullToRefreshScrollView;

import com.nostra13.universalp_w_picpathloader.core.DisplayImageOptions;

import com.nostra13.universalp_w_picpathloader.core.ImageLoader;

public class todayFragment extends Fragment  

{

private ListViewForScrollView mlistmnue;

private PullToRefreshScrollView mScrollview;

protected ImageLoader p_w_picpathLoader = ImageLoader.getInstance();

private ArrayList  context = new ArrayList();

private String strUrl = Contains.strUrl;

private DisplayImageOptions options;

private mlistmnueAdapter mAdapter;

private TextView mTvall;

private ImageButton mBtnBackTop;

private Button mLocationcity;

    

@Override

  public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) 

  {

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

        InitUI(layout);

Options();

InitScroll(layout);

HttpConn();

return layout;

  }

/*

 *  却接受CityHomeActivity的消息

 */

@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

if(data != null)

{

if(resultCode == 1)

{

String cityName = data.getStringExtra("city");

int end = cityName.indexOf("市");

mLocationcity.setText(cityName.substring(0, end));

}

}else

{

          Toast.makeText(getActivity(), "亲!定位失败哦~~~", Toast.LENGTH_SHORT).show();

}

super.onActivityResult(requestCode, resultCode, data);

}

private void InitUI(View layout) {

mBtnBackTop = (ImageButton) layout.findViewById(R.id.img_backtop);

         mBtnBackTop.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

ScrollView scrollView = (ScrollView) mScrollview.findViewById(R.id.scrollview);

scrollView.smoothScrollTo(0, 0);

}

});

         

//       跳转全部团购页面

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

         find_more.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

                Intent intent = new Intent(getActivity(),AllActivity.class);

startActivity(intent );                      

}

});

         

//       定位城市事件

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

         mLocationcity.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

Intent intent = new Intent(getActivity(),CityHomeActivity.class);

startActivityForResult(intent, 0);

}

});

         

}

 

@SuppressLint("NewApi")

private void HttpConn() {

Listener listener = new Listener() 

{

@Override

public void onResponse(String response) 

{

try {

JSONObject  jsonObj = new JSONObject(response);

JSONArray jsonarr = jsonObj.getJSONArray("deals");

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

   {

   JSONObject jsonObject = jsonarr.getJSONObject(i);

String name = jsonObject.getString("name");

String thumbnail = jsonObject.getString("thumbnail");

String solds = jsonObject.getString("solds");

String price = jsonObject.getString("price");

String value = jsonObject.getString("value");

String title = jsonObject.getString("title");

MenuList menuList = new MenuList(name,thumbnail,solds,price,value,title);

context.add(menuList);

}

} catch (JSONException e) {

e.printStackTrace();

}

mAdapter.notifyDataSetChanged();

}

};

ErrorListener errorListener = new ErrorListener() 

{

@Override

public void onErrorResponse(VolleyError error) 

{

//   Toast.makeText(getActivity(), "网络连接有问题"+error, Toast.LENGTH_SHORT).show();

}

};

volleyGet(strUrl, listener, errorListener);

}

// 下载文件(注意结合ListView 数据设置始终是去设置ListView)

private void volleyGet(String url, Listener listener,

ErrorListener errorListener)

{

RequestQueue queue = MyVolley.getRequestQueue();

StringRequest request =

new StringRequestUTF(Method.GET,url,listener,errorListener);

queue.add(request);

}

//  图片下载前、显示

private void Options() 

{

options = new DisplayImageOptions.Builder()

.showImageOnLoading(R.drawable.about_logo)

.showImageForEmptyUri(R.drawable.about_logo)

.showImageOnFail(R.drawable.about_logo)

.cacheInMemory(true)

.cacheOnDisk(true)

.considerExifParams(true)

// .displayer(new RoundedBitmapDisplayer(8))

.build();

}

 

// 解决ScrollView滑动的问题

private void InitScroll(View layout) {

mlistmnue = (ListViewForScrollView) layout.findViewById(R.id.listViewForScrollView1);

mAdapter = new mlistmnueAdapter();

mlistmnue.setAdapter(mAdapter);

// 使用ScrollView滑动到最顶部

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

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

        

        scrollView.setOnScrollListener(new OnScrollListener() {

@Override

public void onScroll(int scrollY) {

if (scrollY == 0)

{

mBtnBackTop.setVisibility(View.INVISIBLE);

}

else

{

mBtnBackTop.setVisibility(View.VISIBLE);

}

}

});

        

        scrollView.smoothScrollTo(0, 0);

        

        mScrollview.setOnRefreshListener(new OnRefreshListener() {

@Override

public void onRefresh(PullToRefreshBase refreshView) {

new Thread()

{

@Override

public void run() {

try {

Thread.sleep(3000);

} catch (InterruptedException e) {

 

e.printStackTrace();

}

getActivity().runOnUiThread( new Runnable() {

public void run() {

mScrollview.onRefreshComplete();

}

});

}

}.start();

}

});

}   

private ImageView mbackTop;

//    设置适配器

class mlistmnueAdapter extends BaseAdapter

{

@Override

public View getView(int position, View convertView, ViewGroup parent) 

{

ListInfo listInfo = null;

View inflate = null;

if(convertView == null)

{

listInfo = new ListInfo();

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);

 

// 解决如何去实现点击跳到顶部

// mbackTop = (ImageView) inflate.findViewById(R.id.img_backtop);

 

inflate.setTag(listInfo);

}

else

{

inflate = convertView;

listInfo = (ListInfo) inflate.getTag();

}

// scrollView.smoothScrollTo(0, 0);

MenuList menuList = context.get(position);

listInfo.LTiltle.setText(menuList.name);

String img = menuList.thumbnail;

p_w_picpathLoader .displayImage(

img, 

listInfo.mImageView, 

options, 

null);

return inflate;

}

@Override

public int getCount() 

{

return context.size();

}

@Override

public Object getItem(int position) 

{

return null;

}

@Override

public long getItemId(int position) 

{

return 0;

}

}

 

class ListInfo 

{

TextView LTiltle ;

TextView LStore;

TextView LDesContext;

TextView LCurrprice;

TextView LOldprice;

TextView LCount;

ImageView mImageView;

   }

class MenuList 

{

private String name;

private String thumbnail;

private String solds;

private String price;

private String value;

private String address;

public MenuList(String name, String thumbnail, String solds,

String price, String value, String address) {

this.name = name;

this.thumbnail = thumbnail;

this.solds = solds;

this.price = price;

this.value = value;

this.address = address;

}

@Override

public String toString() {

return "MenuList [name=" + name + ", img=" + thumbnail + ", solds="

+ solds + ", price=" + price + ", value=" + value

+ ", address=" + address + "]";

}

}

 

}


名称栏目:android开源项目(城市定位)
标题路径:http://cdkjz.cn/article/ppohse.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220