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.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.ArrayList;
import java.util.HashMap;
public class PostbackAdapter extends BaseAdapter {
/**
* 上下文对象的引用
*/
private Context context;
/**
* 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;
// public void setUrls(String[] imageThumbUrls){this.imageThumbUrls=imageThumbUrls;}
//public void setlist(ArrayList<ProductEntity> list){this.mList=list;}
public PostbackAdapter(Context context, ArrayList<HashMap<String, Object>> listData, DisplayMetrics displayMetrics){
this.context = context;
// this.imageThumbUrls = imageThumbUrls;
this.listData=listData;
// this.mList=list;
isFirstEnter=true;
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;
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);
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());
String[] imageThumbUrls=new String[7];
imageThumbUrls[0]="http://pica.nipic.com/2007-11-09/200711912453162_2.jpg";
imageThumbUrls[1]="http://pica.nipic.com/2007-11-09/200711912453162_2.jpg";
imageThumbUrls[2]="http://pica.nipic.com/2007-11-09/200711912453162_2.jpg";
imageThumbUrls[3]="http://pica.nipic.com/2007-11-09/200711912453162_2.jpg";
imageThumbUrls[4]="http://pica.nipic.com/2007-11-09/200711912453162_2.jpg";
imageThumbUrls[5]="http://pica.nipic.com/2007-11-09/200711912453162_2.jpg";
imageThumbUrls[6]="http://pica.nipic.com/2007-11-09/200711912453162_2.jpg";
ImageAdapter1 adapter1=new ImageAdapter1(context,gridView,imageThumbUrls,displaysMetrics);
gridView.setAdapter(adapter1);
/* ImageView mImageView;
TextView tvView;
final String mImageUrl = imageThumbUrls[position];
// final ProductEntity pro;
// if(!mList.isEmpty()&&mList.get(position)!=null)
// pro=mList.get(position);
// else
// pro=null;
View view;
if (convertView == null) {
view = mLayoutInflater.inflate(R.layout.gridview_item,parent,false);
} else {
view = convertView;
}
mImageView=(ImageView)view.findViewById(R.id.ItemImage);
//tvView=(TextView)view.findViewById(R.id.tvTitle);
//tvView.setText(pro.getProName());
mImageView.setLayoutParams(new RelativeLayout.LayoutParams(displaysMetrics.widthPixels/3,displaysMetrics.heightPixels/5));;
//给ImageView设置Tag,这里已经是司空见惯了
mImageView.setTag(mImageUrl);
ImageLoader.getInstance().displayImage(mImageUrl, mImageView);
mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
// mImageView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent intent=new Intent();
// intent.putExtra("ProductName",pro.getProName());
// intent.setClass(context, ProductdetailActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(intent);
// }
// });
*/
return view;
}
}
listView里面添加gridview
最新推荐文章于 2021-11-19 15:19:09 发布