0

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();
124697
  • 22,097
  • 68
  • 188
  • 315

3 Answers3

1

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

ckozl
  • 6,751
  • 3
  • 33
  • 50
0

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?

Community
  • 1
  • 1
Goofy
  • 6,098
  • 17
  • 90
  • 156
  • What does an attribute set look like. say I want to place it in the middle of the screen? – 124697 Jul 03 '12 at 18:31
  • 1
    That has to do with the layout of your activity not with the progress bar itself ... say for RelativLayout -> centerInParent="true" for example. – s.krueger Jul 03 '12 at 18:32
0

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.

Stan
  • 6,511
  • 8
  • 55
  • 87