/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/MyAdapter
package com.bwei.fengkai.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import com.bwei.fengkai.fragment.Fragment1;
import com.bwei.fengkai.fragment.Fragment2;
import com.bwei.fengkai.fragment.Fragment3;
import com.bwei.fengkai.fragment.Fragment4;
import java.util.List;
public class MyAdapter extends FragmentStatePagerAdapter {
private List<String> list;
public MyAdapter(FragmentManager fm, List<String> list) {
super(fm);
this.list = list;
}
@Override
public Fragment getItem(int position) {
Fragment fragment=null;
switch (position){
case 0:
fragment=new Fragment1();
break;
case 1:
fragment=new Fragment2();
break;
case 2:
fragment=new Fragment3();
break;
case 3:
fragment=new Fragment4();
break;
}
return fragment;
}
@Override
public int getCount() {
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
return list.get(position);
}
}
/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&7/MyAdapter2
package com.bwei.fengkai.adapter;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
public class MyAdapter2 extends PagerAdapter {
private List<String> list;
private Context context;
public MyAdapter2(List<String> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
DisplayImageOptions options=new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
ImageLoader.getInstance().displayImage(list.get(position%list.size()),imageView,options);
container.addView(imageView);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/MyfinalAdapter
package com.bwei.fengkai.adapter;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bwei.fengkai.MyroundDrawable;
import com.bwei.fengkai.R;
import com.bwei.fengkai.fragment.bean.Bean;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import java.util.List;
public class MyfinalAdapter extends RecyclerView.Adapter {
List<Bean.StoriesBean> list;
public MyfinalAdapter(List<Bean.StoriesBean> list) {
this.list = list;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType){
case 0:
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item3, parent, false);
RecyclerView.ViewHolder holder3=new MyViewHoler3(view);
return holder3;
case 1:
View view2 = LayoutInflater.from(parent.getContext()).inflate(R.layout.item4, parent, false);
RecyclerView.ViewHolder holder4=new MyViewHoler4(view2);
return holder4;
}
return null;
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
int type = holder.getItemViewType();
switch (type){
case 0:
final MyViewHoler3 holer3= (MyViewHoler3) holder;
holer3.textView.setText(list.get(position).getTitle());
ImageLoader.getInstance().displayImage(list.get(position).getImages().get(0), holer3.imageView, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
holer3.imageView.setImageDrawable(new MyroundDrawable(loadedImage));
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
break;
case 1:
final MyViewHoler4 holer4= (MyViewHoler4) holder;
holer4.textView.setText(list.get(position).getTitle());
ImageLoader.getInstance().displayImage(list.get(position).getImages().get(0), holer4.imageView, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
holer4.imageView.setImageDrawable(new MyroundDrawable(loadedImage));
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
break;
}
}
@Override
public int getItemViewType(int position) {
return position%2==0?0:1;
}
@Override
public int getItemCount() {
return list.size();
}
}
class MyViewHoler3 extends RecyclerView.ViewHolder{
TextView textView;
ImageView imageView;
public MyViewHoler3(View itemView) {
super(itemView);
textView= (TextView) itemView.findViewById(R.id.text3);
imageView=(ImageView) itemView.findViewById(R.id.image3);
}
}
class MyViewHoler4 extends RecyclerView.ViewHolder{
TextView textView;
ImageView imageView;
public MyViewHoler4(View itemView) {
super(itemView);
textView= (TextView) itemView.findViewById(R.id.text4);
imageView=(ImageView) itemView.findViewById(R.id.image4);
}
}
/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/MyGrideAdapter
package com.bwei.fengkai.adapter;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bwei.fengkai.MyDrawable;
import com.bwei.fengkai.R;
import com.bwei.fengkai.fragment.bean.Bean4;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import java.util.List;
public class MyGrideAdapter extends RecyclerView.Adapter<MyViewHolder2> {
List<Bean4.OthersBean> list;
public MyGrideAdapter(List<Bean4.OthersBean> list) {
this.list = list;
}
@Override
public MyViewHolder2 onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item2, parent, false);
MyViewHolder2 holder2=new MyViewHolder2(view);
return holder2;
}
@Override
public void onBindViewHolder(final MyViewHolder2 holder, final int position) {
holder.textView.setText(list.get(position).getName());
ImageLoader.getInstance().displayImage(list.get(position).getThumbnail(), holder.imageView, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
holder.imageView.setImageDrawable(new MyDrawable(loadedImage));
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
longClickListener.onmyLongClick(position,v);
return false;
}
});
}
private onMyLongClickListener longClickListener;
public void setLongClickListener(onMyLongClickListener longClickListener) {
this.longClickListener = longClickListener;
}
public interface onMyLongClickListener{
void onmyLongClick(int pos,View v);
}
@Override
public int getItemCount() {
return list.size();
}
}
class MyViewHolder2 extends RecyclerView.ViewHolder{
TextView textView;
ImageView imageView;
public MyViewHolder2(View itemView) {
super(itemView);
textView= (TextView) itemView.findViewById(R.id.text2);
imageView=(ImageView) itemView.findViewById(R.id.image2);
}
}
/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/MyRecyclerViewAdapter
package com.bwei.fengkai.adapter;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bwei.fengkai.R;
import com.bwei.fengkai.fragment.bean.Bean3;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.CircleBitmapDisplayer;
import java.util.List;
public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyViewHolder>{
private List<Bean3.DataBean> list;
public MyRecyclerViewAdapter( List<Bean3.DataBean> list) {
this.list = list;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
MyViewHolder myViewHolder=new MyViewHolder(view);
return myViewHolder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.textView.setText(list.get(position).getNews_title());
DisplayImageOptions options=new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisk(true)
.displayer(new CircleBitmapDisplayer())
.build();
ImageLoader.getInstance().displayImage(list.get(position).getPic_url(),holder.imageView,options);
// String pic_url = list.get(position).getPic_url();
// try {
// URL url=new URL(pic_url);
//
// HttpURLConnection conn = (HttpURLConnection) url
// .openConnection();
// conn.setRequestMethod("GET");
// conn.setConnectTimeout(5000);
// conn.setReadTimeout(5000);
//
//
// conn.connect();
// InputStream is = conn.getInputStream();
// Bitmap bitmap = BitmapFactory.decodeStream(is);
// holder.imageView.setMaxWidth(50);
// holder.imageView.setMaxHeight(50);
//
// holder.imageView.setImageDrawable(new MyDrawable(bitmap));
//
// } catch (Exception e) {
// e.printStackTrace();
// }
}
@Override
public int getItemCount() {
return list.size();
}
public void loadmore( List<Bean3.DataBean> data,boolean b){
if(b){
list.addAll(0,list);
}else{
list.addAll(data);
}
}
}
class MyViewHolder extends RecyclerView.ViewHolder{
TextView textView;
ImageView imageView;
public MyViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.text);
imageView=(ImageView)itemView.findViewById(R.id.image);
}
}
/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/MyApplication
package com.bwei.fengkai.application;
import android.app.Application;
import android.os.Environment;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import org.xutils.x;
import java.io.File;
public class MyApplication extends Application {
private static MyApplication myApplication;
@Override
public void onCreate() {
super.onCreate();
x.Ext.init(this);
String path= Environment.getExternalStorageDirectory()+"/yuekao";
File file=new File(path);
myApplication=this;
ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(this)//
.diskCacheSize(50*1024*1024)
.memoryCacheExtraOptions(50,50)
.threadPoolSize(3)
.threadPriority(10)
.memoryCacheSize(2*1024*1024)
.diskCacheFileCount(20)
.diskCacheFileNameGenerator(new Md5FileNameGenerator())
.diskCache(new UnlimitedDiskCache(file))
.build();
ImageLoader.getInstance().init(configuration);
}
public static MyApplication getapp(){
return myApplication;
}
}
/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%/