private class listAdapter extends BaseAdapter {
@Override
public int getCount() {
return labels.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
TextView name, type, time, date, location, comm, spot, spottype;
TextView oname, oreg, otype, odate, otime, olocation;
final ImageView pic1;
final ImageView pic2;
final ImageView pic3;
ImageView ovtype, sloc;
ImageLoadingListener animateFirstListener = new AnimateFirstDisplayListener();
int j = 0, x = 0;
if (convertView == null) {
vv = getActivity().getLayoutInflater().inflate(
R.layout.other_item, null);
} else {
vv = convertView;
}
pic1 = (ImageView) vv.findViewById(R.id.pic1);
pic2 = (ImageView) vv.findViewById(R.id.pic2);
pic3 = (ImageView) vv.findViewById(R.id.pic3);
name = (TextView) vv.findViewById(R.id.sname);
type = (TextView) vv.findViewById(R.id.stype);
time = (TextView) vv.findViewById(R.id.stime);
date = (TextView) vv.findViewById(R.id.sdate);
location = (TextView) vv.findViewById(R.id.slocation);
comm = (TextView) vv.findViewById(R.id.scomm);
// spot = (TextView) vv.findViewById(R.id.sspot);
spottype = (TextView) vv.findViewById(R.id.textView1);
oname = (TextView) vv.findViewById(R.id.name);
oreg = (TextView) vv.findViewById(R.id.reg);
otype = (TextView) vv.findViewById(R.id.type);
odate = (TextView) vv.findViewById(R.id.date);
otime = (TextView) vv.findViewById(R.id.time);
olocation = (TextView) vv.findViewById(R.id.location);
ovtype = (ImageView) vv.findViewById(R.id.vtype);
sloc = (ImageView) vv.findViewById(R.id.imageView2);
oname.setText(testimonialData.get(position).getmake() + " "
+ testimonialData.get(position).getmodel());
if (testimonialData.get(position).gettype()
.equalsIgnoreCase("report")) {
oreg.setText("Reg No:" + " "
+ testimonialData.get(position).getReg());
} else {
oreg.setText("Ser No:" + " "
+ testimonialData.get(position).getReg());
}
otype.setText(testimonialData.get(position).getRtype());
odate.setText(dateformate(testimonialData.get(position).getdate()));
otime.setText(testimonialData.get(position).getTime());
olocation.setText(testimonialData.get(position).getsloc());
comm.setText(testimonialData.get(position).getComm());
if (testimonialData.get(position).getVtype()
.equalsIgnoreCase("Car")) {
ovtype.setImageResource(R.drawable.ic_car);
} else if (testimonialData.get(position).getVtype()
.equalsIgnoreCase("Bicycle")) {
ovtype.setImageResource(R.drawable.ic_cycle);
oreg.setText("Ser No:" + " "
+ testimonialData.get(position).getReg());
} else if (testimonialData.get(position).getVtype()
.equalsIgnoreCase("MotorCycle")) {
ovtype.setImageResource(R.drawable.ic_bike);
} else {
ovtype.setImageResource(R.drawable.ic_other);
}
if (comm.getText().toString().isEmpty()) {
comm.setVisibility(View.GONE);
}
if (olocation.getText().toString().isEmpty()) {
olocation.setVisibility(View.GONE);
sloc.setVisibility(View.GONE);
}
String[] imageUrls = { testimonialData.get(position).getp1(),
testimonialData.get(position).getp2(),
testimonialData.get(position).getp3() };
if (!imageUrls[0].isEmpty() && !imageUrls[0].equalsIgnoreCase("")) {
Updates.imageLoader.displayImage(imageUrls[0], pic1, options,
animateFirstListener);
pic1.setVisibility(View.VISIBLE);
pic1.setTag(imageUrls[0]);
if (!imageUrls[1].isEmpty()
&& !imageUrls[1].equalsIgnoreCase("")) {
Updates.imageLoader.displayImage(imageUrls[1], pic2,
options, animateFirstListener);
pic2.setVisibility(View.VISIBLE);
pic2.setTag(imageUrls[1]);
if (!imageUrls[2].isEmpty()
&& !imageUrls[2].equalsIgnoreCase("")) {
Updates.imageLoader.displayImage(imageUrls[2], pic3,
options, animateFirstListener);
pic3.setVisibility(View.VISIBLE);
pic3.setTag(imageUrls[2]);
} else {
pic3.setVisibility(View.GONE);
}
} else {
pic2.setVisibility(View.GONE);
}
} else {
pic1.setVisibility(View.GONE);
// pic2.setVisibility(View.GONE);
}
if (comm.getVisibility() == View.VISIBLE
|| (pic1.getVisibility() == View.VISIBLE
|| pic2.getVisibility() == View.VISIBLE || pic3
.getVisibility() == View.VISIBLE)) {
RelativeLayout rline = (RelativeLayout) vv
.findViewById(R.id.rline);
rline.setVisibility(View.VISIBLE);
}
pic1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), Fullimage.class);
// Toast.makeText(getActivity(), "1", Toast.LENGTH_LONG)
// .show();
intent.putExtra("IMAGES", String.valueOf(pic1.getTag()));
startActivity(intent);
}
});
pic2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), Fullimage.class);
intent.putExtra("IMAGES", String.valueOf(pic2.getTag()));
// Toast.makeText(getActivity(), "2", Toast.LENGTH_LONG)
// .show();
startActivity(intent);
}
});
pic3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), Fullimage.class);
intent.putExtra("IMAGES", String.valueOf(pic3.getTag()));
startActivity(intent);
// Toast.makeText(getActivity(), "3", Toast.LENGTH_LONG)
// .show();
}
});
vv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (testimonialData.get(position).gettype()
.equalsIgnoreCase("report")) {
vid = testimonialData.get(position).getVid();
vmake = testimonialData.get(position).getmake();
vmodel = testimonialData.get(position).getmodel();
vreg = testimonialData.get(position).getReg();
vdate = testimonialData.get(position).getdate();
vtime = testimonialData.get(position).getTime();
vcomm = testimonialData.get(position).getComm();
vloc = testimonialData.get(position).getsloc();
vtypes = testimonialData.get(position).getVtype();
rtype = testimonialData.get(position).getRtype();
spic1 = testimonialData.get(position).getp1();
spic2 = testimonialData.get(position).getp2();
spic3 = testimonialData.get(position).getp3();
IsInternetPresent = cd.isConnectingToInternet();
if (IsInternetPresent == false) {
cd.showNoInternetPopup();
} else {
vinfo = new getvinfo().execute();
}
} else {
}
}
});
return vv;
}
}
上面的代码正在运行。 但是在这个图像中滚动时拖曳,所以我添加了以下行
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
但在添加此行后,它给出了java.lang.ArrayIndexOutOfBoundsException ...
但是如果我删除了getViewTypeCount和getItemViewType方法,那么滚动时图像会随机播放
更新: - 如果我设置getViewTypeCount = 200然后它的工作。所以任何人都可以告诉我getViewTypeCount()只调用一次吗?