溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

android 開源項(xiàng)目(城市定位)

發(fā)布時(shí)間:2020-07-19 16:52:07 來源:網(wǎng)絡(luò) 閱讀:1418 作者:風(fēng)清揚(yáng)lfg 欄目:移動(dòng)開發(fā)

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

}

});

         

//       跳轉(zhuǎn)全部團(tuán)購頁面

         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(), "網(wǎng)絡(luò)連接有問題"+error, Toast.LENGTH_SHORT).show();

}

};

volleyGet(strUrl, listener, errorListener);

}


// 下載文件(注意結(jié)合ListView 數(shù)據(jù)設(shè)置始終是去設(shè)置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滑動(dòng)的問題

private void InitScroll(View layout) {

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

mAdapter = new mlistmnueAdapter();

mlistmnue.setAdapter(mAdapter);

// 使用ScrollView滑動(dòng)到最頂部

        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;

//    設(shè)置適配器

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

 

// 解決如何去實(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);

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 + "]";

}

}

 

}


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI