Sheehan Alam
Sheehan Alam

Reputation: 60859

How to programmatically add a ProgressBar?

I want to put a ProgressBar ontop of a ListView programmatically, and not though the XML editor.

arProgressBar = new ProgressBar(this);

How can I achieve this?

Upvotes: 3

Views: 1296

Answers (2)

viv
viv

Reputation: 6177

Try putting an empty view above listView, then create your progress bar, and try adding it as a child of the empty view.

Upvotes: 1

dmon
dmon

Reputation: 30168

Why can't you just hide it and show it when you need to?

Use: progressBar.setVisibility(View.VISIBLE) and progressBar.setVisibility(View.GONE) to show it/hide it, respectively. Set the android:visibility="gone" in the XML so it's invisible (and does not affect any of the other components' positions) until you need to show it.

Upvotes: 0

Related Questions