This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

AsyncTask used to show progress bar  RSS feed

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a program to show a progress bar using the AsyncTask class. I can see in the Log window the progress in increments of 5, but the progress bar does not show anything. The method showProgress() is activated by a button. Here is the MainActivity class:



And here's the layout file:



What is wrong? What is missing? (The Cancel button does not work either, but this is not my main concern now.) I want to see the progress bar animated. Thank you in advance for help! I really need it!
 
Rancher
Posts: 1926
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tested your code, but look at the documentation of setProgress method. It says Sets the progress for the progress bars in the title.. I guess you need to call setProgess method of ProgressBar class for your own progress bar declared in the xml file.

http://developer.android.com/reference/android/app/Activity.html#setProgress(int)
 
Swastik Dey
Rancher
Posts: 1926
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swastik, thank you for this idea. It almost works, using your suggestions. The only problem is that the bar does not fill up 100%. But I used your suggestion to pay attention to the setProgress function and I got it work!!!

Here's my program now:

 
Swastik Dey
Rancher
Posts: 1926
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi monica,

I tried with your last code, and for its me its filling the complete bar.
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it does. That's what I meant to say. I just did not use exactly your code modification, but I got the idea from your code.
 
Swastik Dey
Rancher
Posts: 1926
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did that in a hurry, any ways it's great that it worked.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To show increment near progress bar and not in logcat?
Thanks
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!