Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create and show ProgressBar programmatically

I have created a ProgressBar programmatically as below in my activity. How do I make it show?

progressBar = new ProgressBar(activity, null, android.R.attr.progressBarStyleSmall);
like image 728
user6304758 Avatar asked Jul 02 '16 13:07

user6304758


2 Answers

You can try this code for adding progressBar programaticlly to your layout.

RelativeLayout layout = new RelativeLayout(this);
ProgressBar progressBar = new ProgressBar(YourActivity.this,null,android.R.attr.progressBarStyleLarge);
progressBar.setIndeterminate(true);
progressBar.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(progressBar,params);

setContentView(layout);
like image 187
motis10 Avatar answered Nov 10 '22 05:11

motis10


progressBar is a widget (view). You need to add to viewgroup.

You can use ProgressDialog to show progress loading Example:

ProgressDialog proDialog = ProgressDialog.show(this, "title", "message");
like image 27
Liem Vo Avatar answered Nov 10 '22 05:11

Liem Vo