1.netutils工具类 package com.example.administrator.utils; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class NetUtils { public static boolean iswangluozj(Context context){ ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo!=null){ return networkInfo.isAvailable(); } return false; } }
2.适配器
package com.example.administrator.adapter; 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.example.administrator.bean.NewsBean; import com.example.administrator.sjk.R; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import java.util.ArrayList; public class MyAdapter extends BaseAdapter { private Context context; private ArrayList<NewsBean.DataBean> list; public MyAdapter(Context context, ArrayList<NewsBean.DataBean> list) { this.context = context; this.list = list; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder=null; if (convertView==null){ convertView = View.inflate(context, R.layout.item, null); holder = new ViewHolder(); holder.text_view = (TextView)convertView.findViewById(R.id.text_view); holder.image = (ImageView)convertView.findViewById(R.id.image); convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } holder.text_view.setText(list.get(position).getBrief()); ImageLoader.getInstance().displayImage(list.get(position).getMiniimg().get(0).getSrc(),holder.image); return convertView; } public class ViewHolder{ public TextView text_view; public ImageView image; } }