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.universalimageloader.core.DisplayImageOptions;

import com.nostra13.universalimageloader.core.ImageLoader;

public class todayFragment extends Fragment

{

private ListViewForScrollView mlistmnue;

private PullToRefreshScrollView mScrollview;

protected ImageLoader imageLoader = ImageLoader.getInstance();

private ArrayList<MenuList>  context = new ArrayList<todayFragment.MenuList>();

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<String> listener = new Listener<String>()

{

@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<String> 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.image_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;

imageLoader .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 开源项目(城市定位)

时间: 2024-10-17 13:01:40

android 开源项目(城市定位)的相关文章

优秀的 Android 开源项目

摘要  转载http://www.trinea.cn/android/android-open-source-projects-view/,方便大家找到自己合适的资料 目录[-] 一.ListView 二.ActionBar 三.Menu 四.ViewPager .Gallery 五.GridView 六.ImageView 七.ProgressBar 八.其他 GitHub上优秀Android开源项目 3. Android开发神器 1.Xabber客户端 2.oschina客户端 3.手机安全

GitHub 优秀的 Android 开源项目

转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介绍那些不错个性化的View,包含ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar及其它如Dialog.Toast.EditText.TableView.Activity Animation等等. 一.ListView android-pulltorefresh 一个强大的拉动

[转]Android开源项目分类汇总

我喜欢收集源码,如今这个时代,我觉得我们要做的不是做前人做过的事,而是学习他们的经验然后在这基础上创新做出更伟大的事. 转自https://github.com/Trinea/android-open-project Android开源项目第一篇——个性化控件(View)篇  包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar.TextView.ScrollView.TimeView.TipView

GitHub上史上最全的Android开源项目分类汇总

今天在看博客的时候,无意中发现了@Trinea在GitHub上的一个项目Android开源项目分类汇总,由于类容太多了,我没有一个个完整地看完,但是里面介绍的开源项目都非常有参考价值,包括很炫的界面特效设计.个性化控件.工具库.优秀的Android开源项目.开发测试工具.优秀个人和团体等.可以这样说,每一位Andorid开发人员都能从中找到一个或多个适用自己项目的解决方案,消化吸收并加以利用,可以为自己的APP增色不少.文章最后还列出了部分国外著名Android开发者的信息,包括GitHub地址

【转】Android开源项目

Android开源项目第一篇——个性化控件(View)篇  包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar.TextView.其他Android开源项目第二篇——工具库篇  包括依赖注入.图片缓存.网络相关.数据库ORM工具包.Android公共库.高版本向低版本兼容库.多媒体.事件总线.传感器.安全.其他Android开源项目第三篇——优秀项目篇  比较有意思的完整的Android项目Andr

Android 开源项目分类汇总

目前包括: Android 开源项目第一篇--个性化控件(View)篇  包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar.TextView.ScrollView.TimeView.TipView.FlipView.ColorPickView.GraphView.UI Style.其他Android 开源项目第二篇--工具库篇  包括依赖注入.图片缓存.网络请求.数据库 ORM 工具包.Andro

Android开源项目分类汇总

转自https://github.com/Trinea/android-open-project Android开源项目第一篇——个性化控件(View)篇  包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar.TextView.ScrollView.TimeView.TipView.FlipView.ColorPickView.GraphView.UI Style.其他Android开源项目第二篇—

【转】GitHub 优秀的 Android 开源项目

转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.ProgressBar及其他如Dialog.Toast.EditText.TableView.Activity Animation等等. 一.ListView android-pulltorefresh 一个强大的拉动

GitHub 优秀Android 开源项目

阅读目录 1.Xabber客户端 2.oschina客户端 3.手机安全管家 4.星座连萌 5.玲闹铃 6.魔乐盒 7.PWP日历 8.Apollo音乐播放器 9.夏普名片识别 10.高仿人人网 11.简洁天气 12.高仿开心网 13.百度推聊 14.餐厅订餐 15.eoe客户端 16.饭否网客户端 17.imiPhoneWall 18.k9mail 19.MSD音乐 20.高仿爱奇艺 21.企信通 22.高仿生日管家 23.PM25 24.高仿陌陌 25.股民邦 26.CB资讯阅读 27.幽秘