Create a ProgressBar without xml in Android

android, android-progressbar, java

Solution

Change this:

t4 = new ProgressBar(this);

to this:

t4 = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);

Problem

I'm trying to create a progressBar (not a progressBar dialog) using java only. I can't make it work, all I get is: (an image that keep going round in circles) Here is my code: ``` b4 = new Button(this); t4 = new ProgressBar(this); b4.setId(4); b4.setText(SensorData.sensorName[4]); b4.setTypeface(null, 1); b4.setTextSize(15); b4.setGravity(Gravity.LEFT); b4.setTextColor(R.color.black); b4.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon, 0); // down // t4.setId(4); t4.setPadding(20, 10, 10, 10); t4.setIndeterminate(false); t4.setProgress(0); t4.setScrollBarStyle(ProgressBar.SCROLLBARS_OUTSIDE_INSET); t4.setMax(100); t4.setVisibility(t4.VISIBLE); sensorsView.addView(b4, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); sensorsView.addView(t4, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); b4.setOnClickListener(this); ``` What I want is an horizontal progressBar, do you know how can I do that? Thanks.

Original source