Reputation: 21893
a progess bar does not come up on the screen with the follow code. why?
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
ProgressBar pBar = new ProgressBar(this, null, android.R.attr.progressBarStyleSmall);
pBar.setLeft(5);
pBar.setTop(5);
pBar.setIndeterminate(true);
pBar.setVisibility(View.VISIBLE);
pBar.bringToFront();
Upvotes: 0
Views: 3162
Reputation: 6551
You have to untie it from the main thread otherwise you really wont see it. I mean if you build it this is the last thing your activity does. If your activity will do something else after trying to display pb you wont see the pb. Usually it works in the following way - MainUI draws the PB and right after that some process starts as async task or as other thread which updates the PB.
As I can see you try to show up the PB on some click/Tap and I guess after that you trying to do something like http-request or some hard calc and this is what you should to start as AT or thread but not as following code which shouldn't display PB.
Upvotes: 0
Reputation: 6761
its looks like you actually want ProgressDialog
but if you actually do want to use ProgressBar
you need to add it to the current view with addView(view)
hope this helps -ck
Upvotes: 1
Reputation: 6128
In the constructor, do this:
ProgressBar pb = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
Check this link also
How to create 'Horizontal style' progress bar programmatically in Android?
Upvotes: 0