标签:
urlEntity: //定义
package com.example.cc.ecustapp.Model;
/**
* Created by weijiawang on 2016/3/8.
*/
public class UrlEntity {
private String[] url;
public void initUrl(int len){
this.url=new String[len];
}
public String[] getUrl(){
return this.url;
}
public void setUrl(String[] url){
this.url=url;
}
fragment: //先把url放到一个Arraylist里面 然后在通过Arraylist调用setUrl方法给UrlEntity赋予url值
private ArrayList<UrlEntity> urlList=new ArrayList<>();
urlEntity.setUrl(picurls);
urlList.add(urlEntity);
}
Adapter: //再从Entity调用geturl方法把url放到Adapter中
package com.example.cc.ecustapp.Adapter;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.example.cc.ecustapp.Model.UrlEntity;
import com.example.cc.ecustapp.R;
import com.example.cc.ecustapp.Service.PostService;
import com.nostra13.universalimageloader.core.ImageLoader;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class PostbackAdapter extends BaseAdapter {
/**
* 上下文对象的引用
*/
private Context context;
private String imageurl="http://59.78.93.208:9095/JoinFunPicture/yanjing2.jpg";
/**
* Image Url的数组
*/
// private String [] imageThumbUrls;
/**
* GridView对象的应用
*/
//private GridView mGridView;
/**
* 记录是否刚打开程序,用于解决进入程序不滚动屏幕,不会下载图片的问题。
* 参考http://blog.csdn.net/guolin_blog/article/details/9526203#comments
*/
private boolean isFirstEnter = true;
/**
* 一屏中第一个item的位置
*/
private int mFirstVisibleItem;
/**
* 一屏中所有item的个数
*/
private int mVisibleItemCount;
private LayoutInflater mLayoutInflater = null;
//private ArrayList<ProductEntity> mList=new ArrayList<>();
private DisplayMetrics displaysMetrics;
private ArrayList<HashMap<String, Object>> listData;
//private String postid;
private String[] urls;
private int Num;
int lastPostid;
private ArrayList<UrlEntity> urlEntities;
JSONArray postsTitilesJsonArray;
PostService postService = new PostService();
String postid;
String postpicid;
private String[] picurls;
String num;
public PostbackAdapter(Context context, ArrayList<UrlEntity> urlEntities,ArrayList<HashMap<String, Object>> listData, DisplayMetrics displayMetrics){
this.context = context;
this.listData=listData;
isFirstEnter=true;
this.urlEntities=urlEntities; //获取Entity
mLayoutInflater=LayoutInflater.from(context);
this.displaysMetrics = displayMetrics;//获取屏幕分辨率
}
@Override
public int getCount() {
return listData.size();
}
@Override
public Object getItem(int position) {
return listData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, final View convertView, ViewGroup parent) {
View view;
if (convertView == null) {
view = mLayoutInflater.inflate(R.layout.post_postback_listview,parent,false);
} else {
view = convertView;
}
TextView tv1,tv2,tv3,tv4;
ImageView touxiang;
NoScrollGridView gridView;
tv1=(TextView)view.findViewById( R.id.textViewPBid);
tv2=(TextView)view.findViewById( R.id.textViewPBText);
tv3=(TextView)view.findViewById(R.id.textViewPBTime);
tv4=(TextView)view.findViewById( R.id.textViewPBUser);
gridView=(NoScrollGridView)view.findViewById(R.id.Gridview_post);
touxiang=(ImageView)view.findViewById(R.id.touxiang);
HashMap<String,Object> hashMap=listData.get(position);
tv1.setText(hashMap.get("textViewPBid").toString());
tv2.setText(hashMap.get("textViewPBText").toString());
tv3.setText(hashMap.get("textViewPBTime").toString());
tv4.setText(hashMap.get("textViewPBUser").toString());
touxiang.setTag(imageurl);
ImageLoader.getInstance().displayImage(imageurl, touxiang);
UrlEntity urlEntity=urlEntities.get(position);
urls=urlEntity.getUrl();
ImageAdapter1 adapter1=new ImageAdapter1(context,gridView,urls,displaysMetrics);
gridView.setAdapter(adapter1);
return view;
}
}
标签:
原文地址:http://www.cnblogs.com/to-creat/p/5256128.html