-----------------------------------------------------------------------------------------------------------------------------------------------

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">

<android.support.design.widget.TabLayout

android:id="@+id/tab"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_below="@id/vp"
android:layout_weight="1"
app:tabBackground="@color/colorPrimaryDark"
app:tabSelectedTextColor="#ff0033"
app:tabTextColor="#00ff96">

</android.support.design.widget.TabLayout>


</LinearLayout>

<android.support.v4.view.ViewPager
android:id="@+id/vp"

android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"></android.support.v4.view.ViewPager>

</LinearLayout>
<LinearLayout
android:background="#f00"
android:layout_gravity="start"
android:layout_width="200dp"
android:layout_height="match_parent"></LinearLayout>
</android.support.v4.widget.DrawerLayout>

-----------------------------------------------------------------------------------------------------------------------------------------------

package com.example.lenovo.liughfhfhgfhg;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {

private List<Fragment> fragments;
private List<String> tabs;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//找控件
TabLayout tab = (TabLayout) findViewById(R.id.tab);
ViewPager vp = (ViewPager) findViewById(R.id.vp);
tabs = new ArrayList<>();
tabs.add("首页");
tabs.add("加载");
tabs.add("分类");
tabs.add("咨询");
tabs.add("个人");
//设置 TabLayout模式
tab.setTabMode(TabLayout.MODE_FIXED);
//设置TabLayout标签 添加tab选项卡
tab.addTab(tab.newTab().setText(tabs.get(0)));
tab.addTab(tab.newTab().setText(tabs.get(1)));
tab.addTab(tab.newTab().setText(tabs.get(2)));
tab.addTab(tab.newTab().setText(tabs.get(3)));

fragments = new ArrayList<>();
fragments.add(new Fragment01());
fragments.add(new Fragment02());
fragments.add(new Fragment03());
fragments.add(new Fragment04());
fragments.add(new Fragment05());
MyFragmentAdapter adapter = new MyFragmentAdapter(getSupportFragmentManager());
vp.setAdapter(adapter);
//将TabLayout与ViewPager关联起来
tab.setupWithViewPager(vp);

}

private class MyFragmentAdapter extends FragmentPagerAdapter {

public MyFragmentAdapter(FragmentManager supportFragmentManager) {
super(supportFragmentManager);
}

@Override
public Fragment getItem(int position) {
return fragments.get(position);
}

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

@Override
public CharSequence getPageTitle(int position) {
return tabs.get(position);
}
}
}

-----------------------------------------------------------------------------------------------------------------------------------------------

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.bawei.jane.mxlistview.view.XListView;
import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* Created by lenovo on 2018/7/27.
*/

public class Fragment01 extends Fragment {
private List<String> picUrl;
private XListView xlv;
private int pageIndex=1;//第一页的数据
private String urlpart="http://www.93.gov.cn/93app/data.do?channelId=0&startNum=";

private String url =urlpart + pageIndex;

private MyAdapter adapter;
private List<Result.DataBean> data = new ArrayList<>();
private int operType = 1;
private ViewPager viewpage;

private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int index = viewpage.getCurrentItem();
index++;
viewpage.setCurrentItem(index);
sendEmptyMessageDelayed(0,2000);
}
};

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = View.inflate(getActivity(), R.layout.fragment1, null);
//


picUrl = new ArrayList<>();

xlv = view.findViewById(R.id.xlv);
viewpage = view.findViewById(R.id.vp);

if (NetUtils.isConn(getActivity())) {
initData();
MyTask myTask = new MyTask();
myTask.execute(url);

Toast.makeText(getActivity(), "有网络", Toast.LENGTH_SHORT).show();
//设置适配器
viewpage.setAdapter(new MyPagerAdapter(picUrl, getActivity()));
//设置默认显示页面
viewpage.setCurrentItem(picUrl.size() * 10);
//发消息
handler.sendEmptyMessage(0);


} else {
NetUtils.openDg(getActivity());
}
xlv.setPullRefreshEnable(true);
xlv.setPullLoadEnable(true);
xlv.setXListViewListener(new XListView.IXListViewListener() {
@Override
public void onRefresh() {

pageIndex = 1;
url = urlpart + pageIndex;
//重新赋值
operType = 1;
MyTask myTask = new MyTask();
myTask.execute(url);

}

@Override
public void onLoadMore() {
// 页数增加
pageIndex++;
url = urlpart + pageIndex;
// 重新赋值
operType = 2;
Toast.makeText(getActivity(), "加载更多", Toast.LENGTH_SHORT).show();
MyTask task = new MyTask();
task.execute(url);

}


});
return view;
}

private void initData() {
picUrl.add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=353970577,2929946804&fm=200&gp=0.jpg");
picUrl.add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3382711420,562977377&fm=27&gp=0.jpg");
picUrl.add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2267393344,4258926851&fm=27&gp=0.jpg");
picUrl.add("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1211379323,1253125292&fm=27&gp=0.jpg");
picUrl.add("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1132229679,4204511222&fm=27&gp=0.jpg");
}



class MyTask extends AsyncTask<String,Void,String> {
@Override
protected String doInBackground(String... strings) {
StringBuilder builder = new StringBuilder();
try {
URL url = new URL(strings[0]);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setReadTimeout(5000);
c.setConnectTimeout(5000);
if (c.getResponseCode()==200){
InputStream inputStream = c.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String str;
while ((str=reader.readLine())!=null){
builder.append(str);
}
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return builder.toString();
}

@Override
protected void onPostExecute(String s) {
Gson gson = new Gson();
Result result = gson.fromJson(s, Result.class);

if (operType==1){
data.clear();
}
data.addAll(result.getData());
setAdapter();
//关闭头尾布局
if (operType ==1){
xlv.stopRefresh();
Date date = new Date(System.currentTimeMillis());//获取当前时间
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化时间
String refreShTime = sf.format(date);
xlv.setRefreshTime(refreShTime);//设置刷新时间
}else {
xlv.stopLoadMore();//关闭尾布局

}

}
}
public void setAdapter(){
if (adapter==null){
adapter = new MyAdapter(data,getActivity());
xlv.setAdapter(adapter);
}else {
adapter.notifyDataSetChanged();
}
}
}

 

-----------------------------------------------------------------------------------------------------------------------------------------------

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


<android.support.v4.view.ViewPager


android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="300dp"></android.support.v4.view.ViewPager>


<com.bawei.jane.mxlistview.view.XListView
android:layout_below="@id/vp"
android:id="@+id/xlv"

android:layout_width="match_parent"
android:layout_height="match_parent"

/>


</LinearLayout>

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Created by lenovo on 2018/7/27.
*/

public class Fragment02 extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = View.inflate(getActivity(), R.layout.fragment2, null);
return view;

}
}

-----------------------------------------------------------------------------------------------------------------------------------------------

package com.example.lenovo.liughfhfhgfhg;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

public class MyAdapter extends BaseAdapter {
private List<Result.DataBean> list;
private Context context;
private ImageView img;
private TextView title;

public MyAdapter(List<Result.DataBean> list, Context context) {
this.list = list;
this.context = context;
}

@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 view, ViewGroup viewGroup) {
// view = View.inflate(context,R.layout.item,null );
// img = view.findViewById(R.id.img);
// title = view.findViewById(R.id.title);
// title.setText(list.get(i).getTITLE());

int type = getItemViewType(i);
MyHolader myHolader = null;
MyHolader2 myHolader2 = null;
if (view == null) {
switch (type) {
case 0:
view = View.inflate(context, R.layout.item1, null);
myHolader = new MyHolader();
myHolader.title = view.findViewById(R.id.title);
view.setTag(myHolader);
break;
case 1:
view = View.inflate(context, R.layout.item, null);
myHolader2 = new MyHolader2();
myHolader2.title = view.findViewById(R.id.title);
myHolader2.img = view.findViewById(R.id.img);
view.setTag(myHolader2);
break;
}
} else {
if (type == 0) {
myHolader = (MyHolader) view.getTag();
}
if (type == 1) {
myHolader2 = (MyHolader2) view.getTag();
}

}


if (type == 0) {
//1,赋值
myHolader.title.setText(list.get(i).getTITLE());
}
if (type == 1) {
//2,赋值
myHolader2.title.setText(list.get(i).getTITLE());
ImageLoader.getInstance().displayImage(list.get(i).getIMAGEURL(), myHolader2.img, ImageLoaderUtils.getImageOptions(context));
}


//ImageLoader.getInstance().displayImage(list.get(i).getIMAGEURL(),img, ImageLoaderUtils.getImageOptions(context));
return view;
}

@Override
public int getItemViewType(int position) {
int type = getViewTypeCount();
if (list.get(position).getIMAGEURL() != null) {
return 1;
}
return 0;
}

@Override
public int getViewTypeCount() {
return 2;
}

class MyHolader {
TextView title;


}

class MyHolader2 {
TextView title;
ImageView img;
}

}

 

-----------------------------------------------------------------------------------------------------------------------------------------------

import android.support.annotation.NonNull;
import android.view.View;
import android.content.Context;


import android.support.v4.view.PagerAdapter;


import android.view.ViewGroup;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
* Created by lenovo on 2018/7/21.
*/

public class MyPagerAdapter extends PagerAdapter {
private List<String>urls;
private Context context;

public MyPagerAdapter(List<String> urls, Context context) {
this.urls = urls;
this.context = context;
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view==object;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
//加载显示图片
ImageLoader.getInstance().displayImage(urls.get(position%urls.size()),imageView, ImageLoaderUtils.getImageOptions(context));
container.addView(imageView);
return imageView;
}

@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
}

-----------------------------------------------------------------------------------------------------------------------------------------------

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


<ImageView
android:id="@+id/img"
android:layout_width="30dp"
android:layout_height="30dp" />
<TextView

android:textSize="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/img"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Environment;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.io.File;

/**
* Created by jane on 2017/12/19.
*/

public class ImageLoaderUtils {

/**
* 初使化
* @param context
*/
public static void initImageLoader(Context context){
//自定义
File cachefile=new File(Environment.getExternalStorageDirectory().getPath()+"/image");

ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(context)
.memoryCacheExtraOptions(480, 800)//缓存图片最大的长和宽
.threadPoolSize(2)//线程池的数量
.threadPriority(4)
.memoryCacheSize(20*1024*1024)//设置内存缓存区大小
.diskCacheSize(20*1024*1024)//设置sd卡缓存区大小
.diskCache(new UnlimitedDiscCache(cachefile))//自定义缓存目录
.writeDebugLogs()//打印日志内容
.diskCacheFileNameGenerator(new Md5FileNameGenerator())//给缓存的文件名进行md5加密处理
.build();
ImageLoader.getInstance().init(configuration);


}

/**
* 得到显示图片设置类
* @param context
* @return
*/
public static DisplayImageOptions getImageOptions(Context context){
DisplayImageOptions options=new DisplayImageOptions.Builder()
.cacheInMemory(true)//使用内存缓存
.cacheOnDisk(true)//使用磁盘缓存
.bitmapConfig(Bitmap.Config.RGB_565)//设置图片色彩模式
.imageScaleType(ImageScaleType.EXACTLY)//设置图片的缩放模式
.build();
return options;
}
}

-----------------------------------------------------------------------------------------------------------------------------------------------

import android.app.Application;

/**
* Created by jane on 2017/12/19.
*/

public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
ImageLoaderUtils.initImageLoader(this);
}
}

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

import android.os.AsyncTask;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
* Created by jane on 2017/12/19.
*/

public class MyTask extends AsyncTask<String,Void,String> {
private Icallback icallback;

public MyTask(Icallback icallback) {
this.icallback = icallback;
}

@Override
protected String doInBackground(String... strings) {
StringBuilder builder=new StringBuilder();
try {
URL url=new URL(strings[0]);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();

connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);

if(connection.getResponseCode()==200){
InputStream inputStream = connection.getInputStream();

BufferedReader reader=new BufferedReader(new InputStreamReader(inputStream));
String str;
while ((str=reader.readLine())!=null){
builder.append(str);
}

return builder.toString();

}


} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return null;
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);

icallback.getJsonData(s);


}

//定义一个接口
public interface Icallback{
void getJsonData(String json);
}
}

 

-----------------------------------------------------------------------------------------------------------------------------------------------

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AlertDialog;



/**
* Created by jane on 2017/12/19.
*/

public class NetUtils {

public static boolean isConn(Context context){
boolean result=true;
ConnectivityManager manager=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if(networkInfo!=null && networkInfo.isAvailable()){
result=true;
}else {
result=false;
}
return result;
}

public static void openDg(final Context context){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setIcon(R.mipmap.ic_launcher) //
.setTitle(R.string.app_name) //
.setMessage("当前无网络").setPositiveButton("设置", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// 跳转到系统的网络设置界面
Intent intent = null;
// 先判断当前系统版本
if(android.os.Build.VERSION.SDK_INT > 10){ // 3.0以上
intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
}else{
intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
}
context.startActivity(intent);

}
}).setNegativeButton("知道了", null).show();


}
}

-----------------------------------------------------------------------------------------------------------------------------------------------

 

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.bawei.jane.mxlistview.view.XListView;
import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* Created by lenovo on 2018/7/27.
*/

public class Fragment01 extends Fragment {
private List<String> picUrl;
private XListView xlv;
private int pageIndex=1;//第一页的数据
private String urlpart="http://www.93.gov.cn/93app/data.do?channelId=0&startNum=";

private String url =urlpart + pageIndex;

private MyAdapter adapter;
private List<Result.DataBean> data = new ArrayList<>();
private int operType = 1;
private ViewPager viewpage;

private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int index = viewpage.getCurrentItem();
index++;
viewpage.setCurrentItem(index);
sendEmptyMessageDelayed(0,2000);
}
};
private com.example.lenovo.liughfhfhgfhg.dao dao;

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = View.inflate(getActivity(), R.layout.fragment1, null);
//
picUrl = new ArrayList<>();
xlv = view.findViewById(R.id.xlv);
viewpage = view.findViewById(R.id.vp);
if (NetUtils.isConn(getActivity())) {
initData();
MyTask myTask = new MyTask();
myTask.execute(url);
Toast.makeText(getActivity(), "有网络", Toast.LENGTH_SHORT).show();
//设置适配器
viewpage.setAdapter(new MyPagerAdapter(picUrl, getActivity()));
//设置默认显示页面
viewpage.setCurrentItem(picUrl.size() * 10);
//发消息
handler.sendEmptyMessage(0);
} else {
NetUtils.openDg(getActivity());
}
xlv.setPullRefreshEnable(true);
xlv.setPullLoadEnable(true);
xlv.setXListViewListener(new XListView.IXListViewListener() {
@Override
public void onRefresh() {
pageIndex = 1;
url = urlpart + pageIndex;
//重新赋值
operType = 1;
MyTask myTask = new MyTask();
myTask.execute(url);
}
@Override
public void onLoadMore() {
// 页数增加
pageIndex++;
url = urlpart + pageIndex;
// 重新赋值
operType = 2;
Toast.makeText(getActivity(), "加载更多", Toast.LENGTH_SHORT).show();
MyTask task = new MyTask();
task.execute(url);
}
});
return view;
}

private void initData() {
picUrl.add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=353970577,2929946804&fm=200&gp=0.jpg");
picUrl.add("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3382711420,562977377&fm=27&gp=0.jpg");
picUrl.add("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2267393344,4258926851&fm=27&gp=0.jpg");
picUrl.add("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1211379323,1253125292&fm=27&gp=0.jpg");
picUrl.add("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1132229679,4204511222&fm=27&gp=0.jpg");
}



class MyTask extends AsyncTask<String,Void,String> {
@Override
protected String doInBackground(String... strings) {
StringBuilder builder = new StringBuilder();
try {
URL url = new URL(strings[0]);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setReadTimeout(5000);
c.setConnectTimeout(5000);
if (c.getResponseCode() == 200) {
InputStream inputStream = c.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String str;
while ((str = reader.readLine()) != null) {
builder.append(str);
}
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return builder.toString();
}

@Override
protected void onPostExecute(String s) {
// Log.i("aaaa","1111"+s);

//dao.add(url,s);
preajson(s);
//关闭头尾布局
if (operType == 1) {
xlv.stopRefresh();
Date date = new Date(System.currentTimeMillis());//获取当前时间
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//格式化时间
String refreShTime = sf.format(date);
xlv.setRefreshTime(refreShTime);//设置刷新时间
} else {
xlv.stopLoadMore();//关闭尾布局

}

}
}

private void preajson(String s) {


Gson gson = new Gson();
Result result = gson.fromJson(s, Result.class);

if (operType == 1) {
data.clear();
}
data.addAll(result.getData());
setAdapter();
}

public void setAdapter(){
if (adapter==null){
adapter = new MyAdapter(data,getActivity());
xlv.setAdapter(adapter);
}else {
adapter.notifyDataSetChanged();
dao = new dao(getActivity());
List<news> cha = dao.cha(url);
if(cha!=null){
for (int i = 0; i < cha.size(); i++) {
preajson(cha.get(i).getJson());
}
}else {
if(NetUtils.isConn(getActivity())){

}else {
Toast.makeText(getActivity(),"打开网络",Toast.LENGTH_SHORT).show();
}
}
}
}

}

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

 

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v4.app.FragmentActivity;

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

/**
* Created by lenovo on 2018/7/29.
*/

public class dao {


private final helper helper;
private final SQLiteDatabase db;

public dao(Context context) {
helper = new helper(context);
db = helper.getWritableDatabase();
}
//查询
public List<news> cha (String url){
ArrayList<news> list = new ArrayList<>();
Cursor cursor = db.rawQuery("select * from news where url=?", new String[]{});
while (cursor.moveToNext()){
String url1 = cursor.getString(cursor.getColumnIndex("url"));
String json = cursor.getString(cursor.getColumnIndex("json"));
list.add(new news(url1,json));
}
return list;
}
//添加
public void add(String url,String json){
ContentValues values =new ContentValues();
values.put("url",url);
values.put("json",json);
db.insert("news",null,values);
}
}

-----------------------------------------------------------------------------------------------------------------------------------------------

 

 


public class helper extends SQLiteOpenHelper {
public helper(Context context) {
super(context, "bwie.db", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table news(id integer primary key autoincrement ,url text,json text)");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

 

public class news {
public String url;
public String json;

@Override
public String toString() {
return "news{" +
"url='" + url + '\'' +
", json='" + json + '\'' +
'}';
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getJson() {
return json;
}

public void setJson(String json) {
this.json = json;
}

public news(String url, String json) {

this.url = url;
this.json = json;
}

public news() {
super();
}
}

-----------------------------------------------------------------------------------------------------------------------------------------------

 

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

-----------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

-----------------------------------------------------------------------------------------------------------------------------------------------