Listview Error When Scrolling Down
Solution 1:
You have to remember what positions are downloading, their progress (if you're not showing an indefinite bar), and update those values in your adapter's getView. This actually gets very complicated quickly though- if you want to update the view again when the download finishes, you have to do a lot of very careful coding do to how listviews work and the way they recycle views, or you have to update the whole listview whenever a file finishes downloading or updates progress, which may result in flicker.
Solution 2:
Choose the concept of viewHolder class which hold the state of listview untill the process is complete. Urs main problem is that when u scroll the listview ,view gets refreshs son only it come to initial state.
Class ViewHolder
{
TextView mtext;
Button mButton;
ProgressBar mBar;
}
In getview method initialise the viewholder class
links:
http://developer.android.com/training/improving-layouts/smooth-scrolling.htmlhttp://developer.android.com/training/contacts-provider/display-contact-badge.html
Solution 3:
try something like this...I am using different views for pdf downloading but you can use this concept
Holder holder;
classHolder {
TextView txt_pdfname;
Button btn_download;
ImageView img_pdficon;
}
@Overridepublic View getView(finalint arg0, View arg1, ViewGroup arg2) {
// position=arg0;
View v=arg1;
if (v == null) {
holder = newHolder();
v = layoutInflater.inflate(R.layout.cell_document, arg2,false);
holder.txt_pdfname = (TextView) v.findViewById(R.id.txt_pdfname);
holder.img_pdficon=(ImageView)v.findViewById(R.id.img_pdficon);
holder.btn_download = (Button) v.findViewById(R.id.btn_download);
v.setTag(holder);
} else{
holder = (Holder) v.getTag();
}
File pdfFile=newFile(Environment.getExternalStorageDirectory().toString()+"/fpapdf/"+(pdfUrl[arg0].substring(pdfUrl[arg0].lastIndexOf('/')+1)));
if(pdfFile.exists()){
holder.btn_download.setVisibility(View.INVISIBLE);
}else
holder.btn_download.setVisibility(View.VISIBLE);
holder.txt_pdfname.setText(this.pdfArray[arg0]);
holder.img_pdficon.setImageResource(pdfImage[arg0]);
holder.btn_download.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View v) {
// YOUR CODE HERE
}
});
return v;
}
for more information see this by Romain
Solution 4:
just replace your getView with this, i am removing the if(view==null) by this you'll get every time a new view else than from the tag
@Overridepublic View getView(finalint position, View convertView, ViewGroup parent) {
final ArrayList<String> array=JournalArray.get(position);
final ViewHolder view;
LayoutInflaterinflator= activity.getLayoutInflater();
view = newViewHolder();
convertView = inflator.inflate(R.layout.familylist_item, null);
view.progress=(ProgressBar)convertView.findViewById(R.id.downprogress);
view.txtViewTitle = (TextView) convertView.findViewById(R.id.text);
view.imgViewFlag = (ImageView) convertView.findViewById(R.id.imageView1);
view.imgAR=(Button)convertView.findViewById(R.id.imageAR);
view.imgAR.setTag(view);
view.imgDown=(Button)convertView.findViewById(R.id.imageDown);
view.imgDown.setTag(view);
view.imgPDF=(Button)convertView.findViewById(R.id.imagePDF);
view.imgPDF.setTag(view);
view.progress=(ProgressBar)convertView.findViewById(R.id.downprogress);
view.btnDel=(Button)convertView.findViewById(R.id.btnDel);
view.btnDel.setTag(view);
convertView.setTag(view);
}
Post a Comment for "Listview Error When Scrolling Down"