erzhou

来源:互联网 发布:josh jackson数据 编辑:程序博客网 时间:2024/05/29 11:11

activity_main

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/DrawerLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <chendemin.bwei.com.zhoukaoday02.XListView
            android:id="@+id/techan_xListView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:cacheColorHint="#00000000" >
        </chendemin.bwei.com.zhoukaoday02.XListView>
         <ImageView
             android:id="@+id/image"
             android:layout_width="300dp"
             android:layout_gravity="left"
             android:choiceMode="singleChoice"
             android:layout_height="match_parent"
             android:background="@drawable/b"/>
</android.support.v4.widget.DrawerLayout>


listview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        app:srcCompat="@mipmap/ic_launcher" />


    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />
</LinearLayout>


scenic_item_list

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/colorAccent"
    android:orientation="horizontal" >


    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:src="@mipmap/ic_launcher" />


    <LinearLayout
        android:id="@+id/layout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="15dp"
        android:layout_toRightOf="@id/img"
        android:orientation="horizontal" >


        <TextView
            android:id="@+id/title1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="名称:" />


        <TextView
            android:id="@+id/title2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="" />
    </LinearLayout>


    <LinearLayout
        android:id="@+id/layout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/layout1"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@id/img"
        android:orientation="horizontal" >


        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="地点:" />


        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="" />
    </LinearLayout>


</RelativeLayout>


xlistview_footer

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >


    <RelativeLayout
        android:id="@+id/xlistview_footer_content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dp" >


        <ProgressBar
            android:id="@+id/xlistview_footer_progressbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:visibility="invisible" />


        <TextView
            android:id="@+id/xlistview_footer_hint_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/xlistview_footer_hint_normal" />
    </RelativeLayout>


</LinearLayout>


xlistview_header

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="bottom" >


    <RelativeLayout
        android:id="@+id/xlistview_header_content"
        android:layout_width="fill_parent"
        android:layout_height="60dp" >


        <LinearLayout
            android:id="@+id/xlistview_header_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:orientation="vertical" >


            <TextView
                android:id="@+id/xlistview_header_hint_textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/xlistview_header_hint_normal" />


            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/xlistview_header_last_time"
                    android:textSize="12sp" />


                <TextView
                    android:id="@+id/xlistview_header_time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="12sp" />
            </LinearLayout>
        </LinearLayout>


        <ImageView
            android:id="@+id/xlistview_header_arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@id/xlistview_header_text"
            android:layout_centerVertical="true"
            android:layout_marginLeft="-35dp"
            android:src="@color/colorAccent" />


        <ProgressBar
            android:id="@+id/xlistview_header_progressbar"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignLeft="@id/xlistview_header_text"
            android:layout_centerVertical="true"
            android:layout_marginLeft="-40dp"
            android:visibility="invisible" />
    </RelativeLayout>


</LinearLayout>


ADM

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="chendemin.bwei.com.zhoukaoday02">
    <uses-permission android:name="android.permission.INTERNET"/>
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true" android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


</manifest>


ActivityMain

package chendemin.bwei.com.zhoukaoday02;


import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.google.gson.Gson;


import java.util.ArrayList;
import java.util.List;




public class MainActivity extends AppCompatActivity implements XListView.IXListViewListener {


    private Adater adater;
    private List<Goods.ResultBean.RowsBean> list = new ArrayList<>();
    private XListView xListView;
    private Handler handler;
    private DrawerLayout drawerLayout;
    private ImageView iv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        handler = new Handler();
        adater = new Adater();
        xListView.setAdapter(adater);
        initdata();
    }


    private void initView() {
        xListView = (XListView) findViewById(R.id.techan_xListView);
        drawerLayout = (DrawerLayout) findViewById(R.id.DrawerLayout);
        iv = (ImageView) findViewById(R.id.image);
        xListView.setPullLoadEnable(true);
        //接口回调一定要配, 容易忘记;
        xListView.setXListViewListener(this);
    }


    private void initdata() {


        new MyAsyncTaskString().execute("http://api.fang.anjuke.com/m/android/1.3/shouye/recInfosV3/?city_id=14&lat=40.04652&lng=116.306033&api_key=androidkey&sig=9317e9634b5fbc16078ab07abb6661c5&macid=45cd2478331b184ff0e15f29aaa89e3e&app=a-ajk&_pid=11738&o=PE-TL10-user+4.4.2+HuaweiPE-TL10+CHNC00B260+ota-rel-keys%2Crelease-keys&from=mobile&m=Android-PE-TL10&cv=9.5.1&cid=14&i=864601026706713&v=4.4.2&pm=b61&uuid=1848c59c-185d-48d9-b0e9-782016041109&_chat_id=0&qtime=20160411091603");
    }


    class Adater extends BaseAdapter {
        public Adater() {
            super();
        }


        @Override
        public int getCount() {
            return list.size();
        }


        @Override
        public Object getItem(int i) {
            return list.get(i);
        }


        @Override
        public long getItemId(int i) {
            return i;
        }


        @Override
        public View getView(int i, View containerView, ViewGroup viewGroup) {
            containerView = View.inflate(MainActivity.this, R.layout.listview, null);
            ImageView imageView = (ImageView) containerView.findViewById(R.id.imageView);
            TextView tv = (TextView) containerView.findViewById(R.id.textView);
            tv.setText(list.get(i).getInfo().getTags());
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    drawerLayout.openDrawer(iv);
                }
            });
            new MyAsyncTaskImage(imageView).execute(list.get(i).getInfo().getDefault_image());
            return containerView;
        }
    }


    class MyAsyncTaskString extends AsyncTask<String, Void, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }


        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            Gson gson = new Gson();
            Goods goods = gson.fromJson(s, Goods.class);


            List<Goods.ResultBean.RowsBean> tempList = goods.getResult().getRows();
            Log.e("wzq", "onPostExecute:tempList "+tempList.size());
            list.addAll(tempList);
            Log.e("wzq", "onPostExecute:list.size() "+list.size());
            adater.notifyDataSetChanged();
        }


        @Override                                       
        protected String doInBackground(String... strings) {
            return new Utiles().getAsytemString(strings[0]);
        }


        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
        }
    }


    class MyAsyncTaskImage extends AsyncTask<String, Void, Bitmap> {
        private ImageView image;


        public MyAsyncTaskImage(ImageView image) {
            this.image = image;
        }


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }


        @Override
        protected void onPostExecute(Bitmap bitmap) {
            super.onPostExecute(bitmap);
            image.setImageBitmap(bitmap);
        }


        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
        }


        @Override
        protected Bitmap doInBackground(String... strings) {
            return new Utiles().getAsytemImage(strings[0]);
        }
    }


    // 关闭
    public void onLoad() {
        xListView.stopRefresh();
        xListView.stopLoadMore();
        xListView.setRefreshTime("刚刚");
    }


    //刷新
    @Override
    public void onRefresh() {
        list.clear();
        initdata();
        onLoad();
    }


    //加载更多
    @Override
    public void onLoadMore() {
        //1--保留之前集合中的数据


        //2 把新数据添加到list中,更新适配器;
        initdata();
        onLoad();


    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            this.finish();
        }
        return false;
    }
}


Utils

package chendemin.bwei.com.zhoukaoday02;


import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


/**
 * author:Created by WangZhiQiang on 2017/9/8.
 */


public class Utiles {
    public Bitmap getAsytemImage(String filename){
        try {
            URL url = new URL(filename);
           HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            int code = urlConnection.getResponseCode();
            if(code==200){
                InputStream inputStream = urlConnection.getInputStream();
                Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                return bitmap;


            }else{
                Log.e("CDM", "getAsytemImage: code"+code);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public String getAsytemString(String filename){
        try {
            URL url = new URL(filename);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            int code = urlConnection.getResponseCode();
            if(code==200){
                InputStream inputStream = urlConnection.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                StringBuilder builder = new StringBuilder();
                String temp="";
                while((temp=reader.readLine())!=null){
                    builder.append(temp);
                }
                String stringBuilder = builder.toString();
                return  stringBuilder;
            }else{
                Log.e("CDM", "getAsytemImage: code"+code);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}


XListView

package chendemin.bwei.com.zhoukaoday02;


import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.animation.DecelerateInterpolator;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Scroller;
import android.widget.TextView;


import java.text.SimpleDateFormat;
import java.util.Date;
public class XListView extends ListView implements OnScrollListener {
private float mLastY = -1; // save event y
private Scroller mScroller; // 用于回滚
private OnScrollListener mScrollListener; // 回滚监听
// 触发刷新和加载更多接口.
private IXListViewListener mListViewListener;
// -- 头部的View
private XListViewHeader mHeaderView;
// 查看头部的内容,用它计算头部高度,和隐藏它
// 当禁用的时候刷新
private RelativeLayout mHeaderViewContent;
private TextView mHeaderTimeView;
private int mHeaderViewHeight; // 头部View的高
private boolean mEnablePullRefresh = true;
private boolean mPullRefreshing = false; // 是否刷新.
// -- 底部的View
private XListViewFooter mFooterView;
private boolean mEnablePullLoad;
private boolean mPullLoading;
private boolean mIsFooterReady = false;
// 总列表项,用于检测列表视图的底部
private int mTotalItemCount;


// for mScroller, 滚动页眉或者页脚
private int mScrollBack;
private final static int SCROLLBACK_HEADER = 0;// 顶部
private final static int SCROLLBACK_FOOTER = 1;// 下部


private final static int SCROLL_DURATION = 400; // 滚动回时间
private final static int PULL_LOAD_MORE_DELTA = 50; // 当大于50PX的时候,加载更多


private final static float OFFSET_RADIO = 1.8f; // support iOS like pull
// feature.


/**
* @param context
*/
public XListView(Context context) {
super(context);
initWithContext(context);
}


public XListView(Context context, AttributeSet attrs) {
super(context, attrs);
initWithContext(context);
}


public XListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initWithContext(context);
}


private void initWithContext(Context context) {
mScroller = new Scroller(context, new DecelerateInterpolator());
// XListView need the scroll event, and it will dispatch the event to
// user's listener (as a proxy).
super.setOnScrollListener(this);


// 初始化头部View
mHeaderView = new XListViewHeader(context);
mHeaderViewContent = (RelativeLayout) mHeaderView
.findViewById(R.id.xlistview_header_content);
mHeaderTimeView = (TextView) mHeaderView
.findViewById(R.id.xlistview_header_time);
addHeaderView(mHeaderView);// 把头部这个视图添加进去


// 初始化底部的View
mFooterView = new XListViewFooter(context);


// 初始化头部高度
mHeaderView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mHeaderViewHeight = mHeaderViewContent.getHeight();
getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
});
}


@Override
public void setAdapter(ListAdapter adapter) {
// 确定XListViewFooter是最后底部的View, 并且只有一次
if (mIsFooterReady == false) {
mIsFooterReady = true;
addFooterView(mFooterView);
}
super.setAdapter(adapter);
}


/**
* 启用或禁用下拉刷新功能.
*
* @param enable
*/
public void setPullRefreshEnable(boolean enable) {
mEnablePullRefresh = enable;
if (!mEnablePullRefresh) { // 禁用,隐藏内容
mHeaderViewContent.setVisibility(View.INVISIBLE);// 如果为false则隐藏下拉刷新功能
} else {
mHeaderViewContent.setVisibility(View.VISIBLE);// 否则就显示下拉刷新功能
}
}


/**
* 启用或禁用加载更多的功能.
*
* @param enable
*/
public void setPullLoadEnable(boolean enable) {
mEnablePullLoad = enable;
if (!mEnablePullLoad) {
mFooterView.hide();// 隐藏
mFooterView.setOnClickListener(null);
} else {
mPullLoading = false;
mFooterView.show();// 显示
mFooterView.setState( XListViewFooter.STATE_NORMAL);
// both "上拉" 和 "点击" 将调用加载更多.
mFooterView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startLoadMore();
}
});
}
}


/**
* 停止刷新, 重置头视图.
*/
public void stopRefresh() {
if (mPullRefreshing == true) {
mPullRefreshing = false;
resetHeaderHeight();
}
}


/**
* stop load more, reset footer view.
*/
public void stopLoadMore() {
if (mPullLoading == true) {
mPullLoading = false;
mFooterView.setState( XListViewFooter.STATE_NORMAL);
}
}


/**
* 設置最後一次刷新時間
*
* @param time
*/
@SuppressLint("SimpleDateFormat")
public void setRefreshTime(String time) {
SimpleDateFormat   formatter   =   new   SimpleDateFormat   ("yyyy年MM月dd日   HH:mm:ss     ");
Date   curDate   =   new   Date(System.currentTimeMillis());
//获取当前时间
String   str   =   formatter.format(curDate);
mHeaderTimeView.setText(str);
}


private void invokeOnScrolling() {
if (mScrollListener instanceof OnXScrollListener) {
OnXScrollListener l = (OnXScrollListener) mScrollListener;
l.onXScrolling(this);
}
}


private void updateHeaderHeight(float delta) {
mHeaderView.setVisiableHeight((int) delta
+ mHeaderView.getVisiableHeight());
if (mEnablePullRefresh && !mPullRefreshing) { // 未处于刷新状态,更新箭头
if (mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
mHeaderView.setState( XListViewHeader.STATE_READY);
} else {
mHeaderView.setState( XListViewHeader.STATE_NORMAL);
}
}
setSelection(0); // scroll to top each time
}


/**
* 重置头视图的高度
*/
private void resetHeaderHeight() {
int height = mHeaderView.getVisiableHeight();
if (height == 0) // 不显示.
return;
// 不显示刷新和标题的时候,什么都不显示
if (mPullRefreshing && height <= mHeaderViewHeight) {
return;
}
int finalHeight = 0; // 默认:滚动回头.
// 当滚动回显示所有头标题时候,刷新
if (mPullRefreshing && height > mHeaderViewHeight) {
finalHeight = mHeaderViewHeight;
}
mScrollBack = SCROLLBACK_HEADER;
mScroller.startScroll(0, height, 0, finalHeight - height,
SCROLL_DURATION);
// 触发刷新
invalidate();
}


// 改变底部视图高度
private void updateFooterHeight(float delta) {
int height = mFooterView.getBottomMargin() + (int) delta;
if (mEnablePullLoad && !mPullLoading) {
if (height > PULL_LOAD_MORE_DELTA) { // 高度足以调用加载更多
mFooterView.setState( XListViewFooter.STATE_READY);
} else {
mFooterView.setState( XListViewFooter.STATE_NORMAL);
}
}
mFooterView.setBottomMargin(height);


// setSelection(mTotalItemCount - 1); // scroll to bottom
}


private void resetFooterHeight() {
int bottomMargin = mFooterView.getBottomMargin();
if (bottomMargin > 0) {
mScrollBack = SCROLLBACK_FOOTER;
mScroller.startScroll(0, bottomMargin, 0, -bottomMargin,
SCROLL_DURATION);
invalidate();
}
}


// 开始加载更多
private void startLoadMore() {
mPullLoading = true;
mFooterView.setState( XListViewFooter.STATE_LOADING);
if (mListViewListener != null) {
mListViewListener.onLoadMore();
}
}


// 触发事件
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mLastY == -1) {
mLastY = ev.getRawY();
}


switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mLastY = ev.getRawY();
break;
case MotionEvent.ACTION_MOVE:
final float deltaY = ev.getRawY() - mLastY;
mLastY = ev.getRawY();
System.out.println("数据监测:" + getFirstVisiblePosition() + "---->"
+ getLastVisiblePosition());
if (getFirstVisiblePosition() == 0
&& (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) {
// 第一项显示,标题显示或拉下来.
updateHeaderHeight(deltaY / OFFSET_RADIO);
invokeOnScrolling();
} else if (getLastVisiblePosition() == mTotalItemCount - 1
&& (mFooterView.getBottomMargin() > 0 || deltaY < 0)) {
// 最后一页,已停止或者想拉起
updateFooterHeight(-deltaY / OFFSET_RADIO);
}
break;
default:
mLastY = -1; // 重置
if (getFirstVisiblePosition() == 0) {
// 调用刷新,如果头部视图高度大于设定高度。
if (mEnablePullRefresh
&& mHeaderView.getVisiableHeight() > mHeaderViewHeight) {
mPullRefreshing = true;// 那么刷新
mHeaderView.setState( XListViewHeader.STATE_REFRESHING);
if (mListViewListener != null) {
mListViewListener.onRefresh();
}
}
resetHeaderHeight();// 刷新完毕,重置头部高度,也就是返回上不
}
if (getLastVisiblePosition() == mTotalItemCount - 1) {
// 调用加载更多.
if (mEnablePullLoad
&& mFooterView.getBottomMargin() > PULL_LOAD_MORE_DELTA) {
startLoadMore();// 如果底部视图高度大于可以加载高度,那么就开始加载
}
resetFooterHeight();// 重置加载更多视图高度
}
break;
}
return super.onTouchEvent(ev);
}


@Override
public void computeScroll() {
if (mScroller.computeScrollOffset()) {
if (mScrollBack == SCROLLBACK_HEADER) {
mHeaderView.setVisiableHeight(mScroller.getCurrY());
} else {
mFooterView.setBottomMargin(mScroller.getCurrY());
}
postInvalidate();
invokeOnScrolling();
}
super.computeScroll();
}


@Override
public void setOnScrollListener(OnScrollListener l) {
mScrollListener = l;
}


@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (mScrollListener != null) {
mScrollListener.onScrollStateChanged(view, scrollState);
}
}


@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// 发送到用户的监听器
mTotalItemCount = totalItemCount;
if (mScrollListener != null) {
mScrollListener.onScroll(view, firstVisibleItem, visibleItemCount,
totalItemCount);
}
}


public void setXListViewListener(IXListViewListener l) {
mListViewListener = l;
}


/**
* 你可以监听到列表视图,OnScrollListener 或者这个. 他将会被调用 , 当头部或底部触发的时候
*/
public interface OnXScrollListener extends OnScrollListener {
public void onXScrolling(View view);
}


/**
* 实现这个接口来刷新/负载更多的事件
*/
public interface IXListViewListener {
public void onRefresh();


public void onLoadMore();
}
}


XListViewFooter

package chendemin.bwei.com.zhoukaoday02;


import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;


public class XListViewFooter extends LinearLayout {
public final static int STATE_NORMAL = 0;
public final static int STATE_READY = 1;
public final static int STATE_LOADING = 2;


private Context mContext;


private View mContentView;
private View mProgressBar;
private TextView mHintView;


public XListViewFooter(Context context) {
super(context);
initView(context);
}


public XListViewFooter(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}


public void setState(int state) {
mHintView.setVisibility(View.INVISIBLE);// 开始底部控件都隐藏
mProgressBar.setVisibility(View.INVISIBLE);
mHintView.setVisibility(View.INVISIBLE);
if (state == STATE_READY) {// 如果是第一页状态,那么“查看更多”显示
mHintView.setVisibility(View.VISIBLE);
mHintView.setText(R.string.xlistview_footer_hint_ready);// 松开显示更多
} else if (state == STATE_LOADING) {// 当加载的时候
mProgressBar.setVisibility(View.VISIBLE);// 加载进度条显示
} else {
mHintView.setVisibility(View.VISIBLE);
mHintView.setText(R.string.xlistview_footer_hint_normal);// 查看更多
}
}


public void setBottomMargin(int height) {
if (height < 0)
return;
LayoutParams lp = (LayoutParams) mContentView
.getLayoutParams();
lp.bottomMargin = height;
mContentView.setLayoutParams(lp);
}


public int getBottomMargin() {
LayoutParams lp = (LayoutParams) mContentView
.getLayoutParams();
return lp.bottomMargin;
}


/**
* normal status
*/
public void normal() {
mHintView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}


/**
* loading status
*/
public void loading() {
mHintView.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}


/**
* 当禁用拉加载更多隐藏底部视图
*/
public void hide() {
LayoutParams lp = (LayoutParams) mContentView
.getLayoutParams();
lp.height = 0;
mContentView.setLayoutParams(lp);
}


/**
* 显示底部视图
*/
public void show() {
LayoutParams lp = (LayoutParams) mContentView
.getLayoutParams();
lp.height = LayoutParams.WRAP_CONTENT;
mContentView.setLayoutParams(lp);
}


private void initView(Context context) {
mContext = context;
LinearLayout moreView = (LinearLayout) LayoutInflater.from(mContext)
.inflate(R.layout.xlistview_footer, null);
addView(moreView);
moreView.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));


mContentView = moreView.findViewById(R.id.xlistview_footer_content);
mProgressBar = moreView.findViewById(R.id.xlistview_footer_progressbar);
mHintView = (TextView) moreView
.findViewById(R.id.xlistview_footer_hint_textview);
}


}


XListViewHeader

package chendemin.bwei.com.zhoukaoday02;


import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;


public class XListViewHeader extends LinearLayout {
private LinearLayout mContainer;
private ImageView mArrowImageView;
private ProgressBar mProgressBar;
private TextView mHintTextView;
private int mState = STATE_NORMAL;// 初始状态


private Animation mRotateUpAnim;
private Animation mRotateDownAnim;


private final int ROTATE_ANIM_DURATION = 180;


public final static int STATE_NORMAL = 0;
public final static int STATE_READY = 1;
public final static int STATE_REFRESHING = 2;


public XListViewHeader(Context context) {
super(context);
initView(context);
}


/**
* @param context
* @param attrs
*/
public XListViewHeader(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}


private void initView(Context context) {
// 初始情况,设置下拉刷新view高度为0
LayoutParams lp = new LayoutParams(
LayoutParams.FILL_PARENT, 0);
// 时间TextView
mContainer = (LinearLayout) LayoutInflater.from(context).inflate(
R.layout.xlistview_header, null);
addView(mContainer, lp);
setGravity(Gravity.BOTTOM);
// 找到头部页面里的控件
mArrowImageView = (ImageView) findViewById(R.id.xlistview_header_arrow);
mHintTextView = (TextView) findViewById(R.id.xlistview_header_hint_textview);
mProgressBar = (ProgressBar) findViewById(R.id.xlistview_header_progressbar);


mRotateUpAnim = new RotateAnimation(0.0f, -180.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateUpAnim.setDuration(ROTATE_ANIM_DURATION);
mRotateUpAnim.setFillAfter(true);
mRotateDownAnim = new RotateAnimation(-180.0f, 0.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
mRotateDownAnim.setDuration(ROTATE_ANIM_DURATION);
mRotateDownAnim.setFillAfter(true);
}


// 设置状态
public void setState(int state) {
if (state == mState)
return;


if (state == STATE_REFRESHING) { // 显示进度
mArrowImageView.clearAnimation();
mArrowImageView.setVisibility(View.INVISIBLE);// 不显示图片
mProgressBar.setVisibility(View.VISIBLE);// 显示进度条
} else { // 显示箭头图片
mArrowImageView.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.INVISIBLE);
}


switch (state) {
case STATE_NORMAL:
if (mState == STATE_READY) {// 当状态时准备的时候,显示动画
mArrowImageView.startAnimation(mRotateDownAnim);
}
if (mState == STATE_REFRESHING) {// 当状态显示进度条的时候,清除动画
mArrowImageView.clearAnimation();
}
mHintTextView.setText(R.string.xlistview_header_hint_normal);// 文字提示:下拉刷新
break;
case STATE_READY:
if (mState != STATE_READY) {
mArrowImageView.clearAnimation();
mArrowImageView.startAnimation(mRotateUpAnim);
mHintTextView.setText(R.string.xlistview_header_hint_ready);// 松开刷新数据
}
break;
case STATE_REFRESHING:
mHintTextView.setText(R.string.xlistview_header_hint_loading);
break;
default:
}


mState = state;
}


public void setVisiableHeight(int height) {
if (height < 0)
height = 0;
LayoutParams lp = (LayoutParams) mContainer
.getLayoutParams();
lp.height = height;
mContainer.setLayoutParams(lp);
}


public int getVisiableHeight() {
return mContainer.getHeight();
}


}


Goods

package chendemin.bwei.com.zhoukaoday02;


import java.util.List;


/**
 * author:Created by WangZhiQiang on 2017/9/8.
 */


public class Goods {
    private String status;
    private ResultBean result;


    public String getStatus() {
        return status;
    }


    public void setStatus(String status) {
        this.status = status;
    }


    public ResultBean getResult() {
        return result;
    }


    public void setResult(ResultBean result) {
        this.result = result;
    }


    @Override
    public String toString() {
        return "Goods{" +
                "status='" + status + '\'' +
                ", result=" + result +
                '}';
    }


    public static class ResultBean {
        private String title;
        private String total;
        private int next_page;
        private List<RowsBean> rows;


        public String getTitle() {
            return title;
        }


        public void setTitle(String title) {
            this.title = title;
        }


        public String getTotal() {
            return total;
        }


        public void setTotal(String total) {
            this.total = total;
        }


        public int getNext_page() {
            return next_page;
        }


        public void setNext_page(int next_page) {
            this.next_page = next_page;
        }


        public List<RowsBean> getRows() {
            return rows;
        }


        public void setRows(List<RowsBean> rows) {
            this.rows = rows;
        }


        @Override
        public String toString() {
            return "ResultBean{" +
                    "title='" + title + '\'' +
                    ", total='" + total + '\'' +
                    ", next_page=" + next_page +
                    ", rows=" + rows +
                    '}';
        }


        public static class RowsBean {


            private String fang_type;
            private InfoBean info;


            public String getFang_type() {
                return fang_type;
            }


            public void setFang_type(String fang_type) {
                this.fang_type = fang_type;
            }


            public InfoBean getInfo() {
                return info;
            }


            public void setInfo(InfoBean info) {
                this.info = info;
            }


            @Override
            public String toString() {
                return "RowsBean{" +
                        "fang_type='" + fang_type + '\'' +
                        ", info=" + info +
                        '}';
            }


            public static class InfoBean {
                private String loupan_id;
                private String loupan_name;
                private String city_id;
                private String new_price_value;
                private String new_price_back;
                private int price;
                private String region_id;
                private String region_title;
                private String sub_region_id;
                private String sub_region_title;
                private String default_image;
                private String address;
                private ShowActivityBean show_activity;
                private TuangouBean tuangou;
                private ZhuankftBean zhuankft;
                private KftBean kft;
                private String sale_label;
                private String loupan_property_type;
                private String tags;
                private String status_sale;
                private int has_sale;
                private String lat;
                private String lng;
                private String baidu_lat;
                private String baidu_lng;
                private String kaipan_new_date;
                private ActivityTagsBean activity_tags;
                private int has_consultant;
                private String sale_title;
                private RecommendPriceBean recommend_price;
                private String fang_type;
                private BrandBean brand;
                private int has_video;
                private int has_aerial_photo;
                private int has_quanjing;
                private String area_rage;
                private String jianzhu_area;
                private List<?> activity_tags_icon;
                private List<?> multi_image;
                private List<?> activity;


                public String getLoupan_id() {
                    return loupan_id;
                }


                public void setLoupan_id(String loupan_id) {
                    this.loupan_id = loupan_id;
                }


                public String getLoupan_name() {
                    return loupan_name;
                }


                public void setLoupan_name(String loupan_name) {
                    this.loupan_name = loupan_name;
                }


                public String getCity_id() {
                    return city_id;
                }


                public void setCity_id(String city_id) {
                    this.city_id = city_id;
                }


                public String getNew_price_value() {
                    return new_price_value;
                }


                public void setNew_price_value(String new_price_value) {
                    this.new_price_value = new_price_value;
                }


                public String getNew_price_back() {
                    return new_price_back;
                }


                public void setNew_price_back(String new_price_back) {
                    this.new_price_back = new_price_back;
                }


                public int getPrice() {
                    return price;
                }


                public void setPrice(int price) {
                    this.price = price;
                }


                public String getRegion_id() {
                    return region_id;
                }


                public void setRegion_id(String region_id) {
                    this.region_id = region_id;
                }


                public String getRegion_title() {
                    return region_title;
                }


                public void setRegion_title(String region_title) {
                    this.region_title = region_title;
                }


                public String getSub_region_id() {
                    return sub_region_id;
                }


                public void setSub_region_id(String sub_region_id) {
                    this.sub_region_id = sub_region_id;
                }


                public String getSub_region_title() {
                    return sub_region_title;
                }


                public void setSub_region_title(String sub_region_title) {
                    this.sub_region_title = sub_region_title;
                }


                public String getDefault_image() {
                    return default_image;
                }


                public void setDefault_image(String default_image) {
                    this.default_image = default_image;
                }


                public String getAddress() {
                    return address;
                }


                public void setAddress(String address) {
                    this.address = address;
                }


                public ShowActivityBean getShow_activity() {
                    return show_activity;
                }


                public void setShow_activity(ShowActivityBean show_activity) {
                    this.show_activity = show_activity;
                }


                public TuangouBean getTuangou() {
                    return tuangou;
                }


                public void setTuangou(TuangouBean tuangou) {
                    this.tuangou = tuangou;
                }


                public ZhuankftBean getZhuankft() {
                    return zhuankft;
                }


                public void setZhuankft(ZhuankftBean zhuankft) {
                    this.zhuankft = zhuankft;
                }


                public KftBean getKft() {
                    return kft;
                }


                public void setKft(KftBean kft) {
                    this.kft = kft;
                }


                public String getSale_label() {
                    return sale_label;
                }


                public void setSale_label(String sale_label) {
                    this.sale_label = sale_label;
                }


                public String getLoupan_property_type() {
                    return loupan_property_type;
                }


                public void setLoupan_property_type(String loupan_property_type) {
                    this.loupan_property_type = loupan_property_type;
                }


                public String getTags() {
                    return tags;
                }


                public void setTags(String tags) {
                    this.tags = tags;
                }


                public String getStatus_sale() {
                    return status_sale;
                }


                public void setStatus_sale(String status_sale) {
                    this.status_sale = status_sale;
                }


                public int getHas_sale() {
                    return has_sale;
                }


                public void setHas_sale(int has_sale) {
                    this.has_sale = has_sale;
                }


                public String getLat() {
                    return lat;
                }


                public void setLat(String lat) {
                    this.lat = lat;
                }


                public String getLng() {
                    return lng;
                }


                public void setLng(String lng) {
                    this.lng = lng;
                }


                public String getBaidu_lat() {
                    return baidu_lat;
                }


                public void setBaidu_lat(String baidu_lat) {
                    this.baidu_lat = baidu_lat;
                }


                public String getBaidu_lng() {
                    return baidu_lng;
                }


                public void setBaidu_lng(String baidu_lng) {
                    this.baidu_lng = baidu_lng;
                }


                public String getKaipan_new_date() {
                    return kaipan_new_date;
                }


                public void setKaipan_new_date(String kaipan_new_date) {
                    this.kaipan_new_date = kaipan_new_date;
                }


                public ActivityTagsBean getActivity_tags() {
                    return activity_tags;
                }


                public void setActivity_tags(ActivityTagsBean activity_tags) {
                    this.activity_tags = activity_tags;
                }


                public int getHas_consultant() {
                    return has_consultant;
                }


                public void setHas_consultant(int has_consultant) {
                    this.has_consultant = has_consultant;
                }


                public String getSale_title() {
                    return sale_title;
                }


                public void setSale_title(String sale_title) {
                    this.sale_title = sale_title;
                }


                public RecommendPriceBean getRecommend_price() {
                    return recommend_price;
                }


                public void setRecommend_price(RecommendPriceBean recommend_price) {
                    this.recommend_price = recommend_price;
                }


                public String getFang_type() {
                    return fang_type;
                }


                public void setFang_type(String fang_type) {
                    this.fang_type = fang_type;
                }


                public BrandBean getBrand() {
                    return brand;
                }


                public void setBrand(BrandBean brand) {
                    this.brand = brand;
                }


                public int getHas_video() {
                    return has_video;
                }


                public void setHas_video(int has_video) {
                    this.has_video = has_video;
                }


                public int getHas_aerial_photo() {
                    return has_aerial_photo;
                }


                public void setHas_aerial_photo(int has_aerial_photo) {
                    this.has_aerial_photo = has_aerial_photo;
                }


                public int getHas_quanjing() {
                    return has_quanjing;
                }


                public void setHas_quanjing(int has_quanjing) {
                    this.has_quanjing = has_quanjing;
                }


                public String getArea_rage() {
                    return area_rage;
                }


                public void setArea_rage(String area_rage) {
                    this.area_rage = area_rage;
                }


                public String getJianzhu_area() {
                    return jianzhu_area;
                }


                public void setJianzhu_area(String jianzhu_area) {
                    this.jianzhu_area = jianzhu_area;
                }


                public List<?> getActivity_tags_icon() {
                    return activity_tags_icon;
                }


                public void setActivity_tags_icon(List<?> activity_tags_icon) {
                    this.activity_tags_icon = activity_tags_icon;
                }


                public List<?> getMulti_image() {
                    return multi_image;
                }


                public void setMulti_image(List<?> multi_image) {
                    this.multi_image = multi_image;
                }


                public List<?> getActivity() {
                    return activity;
                }


                public void setActivity(List<?> activity) {
                    this.activity = activity;
                }


                @Override
                public String toString() {
                    return "InfoBean{" +
                            "loupan_id='" + loupan_id + '\'' +
                            ", loupan_name='" + loupan_name + '\'' +
                            ", city_id='" + city_id + '\'' +
                            ", new_price_value='" + new_price_value + '\'' +
                            ", new_price_back='" + new_price_back + '\'' +
                            ", price=" + price +
                            ", region_id='" + region_id + '\'' +
                            ", region_title='" + region_title + '\'' +
                            ", sub_region_id='" + sub_region_id + '\'' +
                            ", sub_region_title='" + sub_region_title + '\'' +
                            ", default_image='" + default_image + '\'' +
                            ", address='" + address + '\'' +
                            ", show_activity=" + show_activity +
                            ", tuangou=" + tuangou +
                            ", zhuankft=" + zhuankft +
                            ", kft=" + kft +
                            ", sale_label='" + sale_label + '\'' +
                            ", loupan_property_type='" + loupan_property_type + '\'' +
                            ", tags='" + tags + '\'' +
                            ", status_sale='" + status_sale + '\'' +
                            ", has_sale=" + has_sale +
                            ", lat='" + lat + '\'' +
                            ", lng='" + lng + '\'' +
                            ", baidu_lat='" + baidu_lat + '\'' +
                            ", baidu_lng='" + baidu_lng + '\'' +
                            ", kaipan_new_date='" + kaipan_new_date + '\'' +
                            ", activity_tags=" + activity_tags +
                            ", has_consultant=" + has_consultant +
                            ", sale_title='" + sale_title + '\'' +
                            ", recommend_price=" + recommend_price +
                            ", fang_type='" + fang_type + '\'' +
                            ", brand=" + brand +
                            ", has_video=" + has_video +
                            ", has_aerial_photo=" + has_aerial_photo +
                            ", has_quanjing=" + has_quanjing +
                            ", area_rage='" + area_rage + '\'' +
                            ", jianzhu_area='" + jianzhu_area + '\'' +
                            ", activity_tags_icon=" + activity_tags_icon +
                            ", multi_image=" + multi_image +
                            ", activity=" + activity +
                            '}';
                }


                public static class ShowActivityBean {
                }


                public static class TuangouBean {
                }


                public static class ZhuankftBean {
                }


                public static class KftBean {
                }


                public static class ActivityTagsBean {
                }


                public static class RecommendPriceBean {
                }


                public static class BrandBean {
                }
            }
        }
    }
}