public View getView(final int pos, View arg1, ViewGroup arg2) {
ViewHolder holder;
View view = arg1;
if (arg1 == null) {
holder = new ViewHolder();
System.out.println("Inflating view");
arg1 = mInflater.inflate(R.layout.inflatefreedownlod, arg2, false);
holder.im = (ImageView) arg1.findViewById(R.id.imf1);
holder.tv1 = (TextView) arg1.findViewById(R.id.tvf1);
holder.tv2 = (TextView) arg1.findViewById(R.id.mini1);
holder.tv3 = (TextView) arg1.findViewById(R.id.m1);
arg1.setTag(holder);
} else {
holder = (ViewHolder) arg1.getTag();
}
holder.tv1.setText(NAME.get(pos).toString());
holder.tv2.setText(contentName.get(pos).toString());
holder.tv3.setText(minidescp.get(pos).toString());
URL url1;
try {
url1 = new URL(imurl.get(pos).toString());
bmp = BitmapFactory.decodeStream(url1.openConnection().getInputStream());
holder.im.setImageBitmap(bmp);
//bmp.recycle();
} catch (Exception e) {
e.printStackTrace();
}
arg1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
for (int i = 0; i < NAME.size(); i++)
if (pos == i) {
getFreeContent(Cid.get(pos).toString(), Vid.get(pos).toString(), contentName.get(pos).toString());
}
}
});
return arg1;
}
I see the logcat which shows Inflating View 3 times. I have 3 LinearLayout displayed in listview when i test it on emulator. Why is my view null everytime?. View also is inflated every time. Anything wrong with my code
If you have three items in your list, and there is space on the screen for three rows in your
ListView,getView()will be called three times with anullViewto create those three rows. You cannot recycle a row that is presently in use.