progress bar only on current item, not on others. when i long clicking on item the progress bar shown on to or more items and changing position. i want show progressbar only on clicked item not other items
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
String getidtoextra = ((TextView) v.findViewById(R.id.wallid)).getText().toString();
final ProgressBar itemprogress = (ProgressBar) v.findViewById(R.id.itemprogress);
itemprogress.setVisibility(View.VISIBLE);
DownloadManager manager = new DownloadManager();
String destPath = Environment.getExternalStorageDirectory() + File.separator + "Kaghaz Divari/" + getidtoextra + "_KD.jpg";
DownloadRequest request = new DownloadRequest()
.setDownloadId(pos)
.setUrl("http://www.wenenus.com/www.samankd.com/android/wallpaper/download.php?id=" + getidtoextra)
.setDestFilePath(destPath)
.setDownloadListener(new DownloadListener() {
@Override
public void onStart(int downloadId, long totalBytes) {
}
@Override
public void onRetry(int downloadId) {
itemprogress.setProgress(0);
}
@Override
public void onProgress(int downloadId, long bytesWritten, long totalBytes) {
itemprogress.setProgress((int) ((bytesWritten * 100) / totalBytes));
}
@Override
public void onSuccess(int downloadId, String filePath) {
itemprogress.setVisibility(View.GONE);
}
@Override
public void onFailure(int downloadId, int statusCode, String errMsg) {
itemprogress.setVisibility(View.GONE);
}
});
manager.add(request);
return onLongListItemClick(v,pos,id);
}
});
My custom adapter
public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Movie> movieItems;
public CustomListAdapter(Activity activity, List<Movie> movieItems) {
this.activity = activity;
this.movieItems = movieItems;
}
@Override
public int getCount() {
return movieItems.size();
}
@Override
public Object getItem(int location) {
return movieItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null) inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) convertView = inflater.inflate(R.layout.list_row, null);
ImageView thumbNail = (ImageView) convertView.findViewById(R.id.thumbnail);
ImageView isdownloaded = (ImageView) convertView.findViewById(R.id.isdownloaded);
LinearLayout newwallpaperarea = (LinearLayout) convertView.findViewById(R.id.newwallpaperarea);
TextView downloads = (TextView)convertView.findViewById(R.id.dlstxt);
TextView rating = (TextView)convertView.findViewById(R.id.ratingtxt);
TextView wallid = (TextView)convertView.findViewById(R.id.wallid);
// getting movie data for the row
Movie m = movieItems.get(position);
File is_wall_dl = new File(Environment.getExternalStorageDirectory()+ "/Kaghaz Divari/"+m.getThumbnailUrl());
File is_wall_dl_id = new File(Environment.getExternalStorageDirectory()+ "/Kaghaz Divari/"+m.getId()+"_KD.jpg");
if(is_wall_dl.exists() || is_wall_dl_id.exists()){
isdownloaded.setVisibility(View.VISIBLE);
}
else{
isdownloaded.setVisibility(View.GONE);
}
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
String tsnew = ts+"000";
long realtime = Long.parseLong(tsnew);
String walldate = m.getDate();
long walldateall = Long.parseLong(walldate);
long walldatefinal = walldateall+86400000;
if (realtime > walldatefinal) {
newwallpaperarea.setVisibility(View.GONE);
} else {
newwallpaperarea.setVisibility(View.VISIBLE);
}
// thumbnail image
Ion.with(thumbNail)
.placeholder(R.drawable.skd_small_bg_200x200)
.error(R.drawable.skd_small_bg_200x200_error)
.load("http://www.wenenus.com/www.samankd.com/android/wallpaper/wallpaper/200/200/80/1/" + m.getThumbnailUrl());
downloads.setText(m.getDownloads());
rating.setText(m.getRating());
wallid.setText(m.getId());
return convertView;
}
}