Android SeekBar (slider)

Hi.
I am trying to implement a java SeekBar programmatically in my sketch but without any success.
Untill now I have the code below, but giving a lot of errors starting with “The constructor SeekBar(seekbar) is undefined”.
I really need some help here.
Thanks in advance.

import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.app.Activity;
import android.content.Context;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.os.Looper;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.os.Bundle;

Activity act;
Context mC;
FrameLayout fl;
SeekBar seekBar;

@ Override 
  public void onStart() {
  super.onStart();
  act = this.getActivity();
  mC= act.getApplicationContext();
  act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
  SeekBar seekBar = new SeekBar(mC);
  Seekbar.setLayoutParams (
    new RelativeLayout.LayoutParams (
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT
    )
    );
  fl = (FrameLayout)act.findViewById(R.id.content);
  FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);  
  fl.addView(seekBar);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      prinln(progress);
      }
   });
  }

The error message talks about something wrong with your constructor. Then, your first stop should be the Android API docs.

I have written an example where changing the slider adjust the alpha transparency of a rectangle showing a linear gradient.

Kf

import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.app.Activity;
import android.content.Context;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.os.Looper;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.os.Bundle;

import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.R;

Activity act;
Context mC;
FrameLayout fl;
SeekBar seekBar;

final color BGCOLOR=color(10, 10, 250);
final int MAX_ALPHA=255;

color beginLGcolor=color(255, 0, 0,255);
color endLGcolor=color(255, 0, 0,0);

void settings() {

  size(displayWidth, displayHeight>>1,P2D);
}



void draw() {
  background(BGCOLOR);
  rectLinearGradient(width*0.25, height*0.25, width*0.75, height*0.75, beginLGcolor, endLGcolor);
}

void rectLinearGradient(float x0, float y0, float x1, float y1, color c1, color c2) {

  if (x0>x1) {
    println("Nothing done as x0, x1 are not valid");
    return;
  }

  if (y0>y1) {
    println("Nothing done as y0, y1 are not valid");
    return;
  }

  pushStyle();
  strokeWeight(1);
  float deltaRow=y1-y0;
  for (float row=y0; row<y1; row++) {
    stroke(lerpColor(c1, c2, (row-y0)/deltaRow));
    line(x0, row, x1, row);
  }
  popStyle();
}

@ Override 
  public void onStart() {

  super.onStart();

  act = this.getActivity();
  mC= act.getApplicationContext();

  act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

  SeekBar seekBar = new SeekBar(mC);

  seekBar.setLayoutParams (
    new RelativeLayout.LayoutParams (
    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT
    )
    );
  seekBar.setPadding(100, 100, 200, 0);
  fl = (FrameLayout)act.findViewById(R.id.content);
  fl.addView(seekBar);

  seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

    @Override
      public void onStartTrackingTouch(SeekBar seekBar) {
      ;
    }

    @Override
      public void onStopTrackingTouch(SeekBar seekBar) {
    }

    @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      println(progress,seekBar.getMax());
      float aFactor=progress/float(seekBar.getMax())*MAX_ALPHA;
      endLGcolor=color(255,0,0,aFactor);
    }
  }
  );
}

1 Like

This next is the same sketch as above but it uses xml to define the SeekBar object. Notice for this you need to follow some instructions at the end of this post. First, I will present the two files: the pde and the xml.

PDE file

import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.app.Activity;
import android.content.Context;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.os.Looper;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.os.Bundle;

import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.R;
import android.view.LayoutInflater;
import android.view.View;

Activity act;
Context mC;
FrameLayout fl;

final color BGCOLOR=color(10, 10, 250);
final int MAX_ALPHA=255;

color beginLGcolor=color(255, 0, 0, 255);
color endLGcolor=color(255, 0, 0, 0);

void settings() {
  size(displayWidth, displayHeight>>1, P2D);
}



void draw() {
  background(BGCOLOR);
  rectLinearGradient(width*0.25, height*0.25, width*0.75, height*0.75, beginLGcolor, endLGcolor);
}

void rectLinearGradient(float x0, float y0, float x1, float y1, color c1, color c2) {

  if (x0>x1) {
    println("Nothing done as x0, x1 are not valid");
    return;
  }

  if (y0>y1) {
    println("Nothing done as y0, y1 are not valid");
    return;
  }

  pushStyle();
  strokeWeight(1);
  float deltaRow=y1-y0;
  for (float row=y0; row<y1; row++) {
    stroke(lerpColor(c1, c2, (row-y0)/deltaRow));
    line(x0, row, x1, row);
  }
  popStyle();
}

@ Override 
  public void onStart() {

  super.onStart();

  act = this.getActivity();
  mC= act.getApplicationContext();

  act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

  LayoutInflater inflater = getActivity().getLayoutInflater();
  final View inflator = inflater.inflate(processing.test.sketch_180625c.R.layout.seekbar_layout, null);   //processing.test.inflatordemo.
  SeekBar seekBar = (SeekBar)inflator.findViewById(processing.test.sketch_180625c.R.id.seekBar);

  seekBar.setPadding(100, 100, 200, 0);
  fl = (FrameLayout)act.findViewById(R.id.content);
  fl.addView(seekBar);

  seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

    @Override
      public void onStartTrackingTouch(SeekBar seekBar) {
      ;
    }

    @Override
      public void onStopTrackingTouch(SeekBar seekBar) {
    }

    @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      println(progress, seekBar.getMax());
      float aFactor=progress/float(seekBar.getMax())*MAX_ALPHA;
      endLGcolor=color(255, 0, 0, aFactor);
      //Toast.makeText(mC, "Progress "+progress, Toast.LENGTH_SHORT).show();
    }
  }
  );
}

XML file

<SeekBar  xmlns:android="http://schemas.android.com/apk/res/android"
	  android:id="@+id/seekBar"  
	  android:layout_width="match_parent"  
	  android:layout_height="wrap_content"
	  android:layout_marginStart="8dp" 
	  android:layout_marginEnd="8dp"           
	  android:layout_marginTop="372dp"  />

REMARKS:

  1. Notice that the name of the sketch is important. In this case, the sketch’s name is sketch_180625c. I am running without saving this test, but for any case, you need to use the name of the actual sketch, or the temp name given by Processing. For the inflator to work, you need to use the package name of your app. In testing mode, Processing Android assigns the package name for you using the following schema: processing.test.sketch_180625c. Notice the sketch name is used here in the last part of this notation. So keep this in mind when modifying or inflating any component defined by an xml file.
  2. The xml needs to be placed in the following folder: res/layout. Notice this folder is not nested inside the data folder. The resultant layout of the project is the following:
C:.
│   AndroidManifest.xml
│   AppLifeCycle.pde
│   sketch.properties
│   sketch_180625c.pde
│
├───code
│       sketch.properties
│
└───res
    └───layout
            seekbar_layout.xml

Kf

1 Like

Thank you so much! The first code is working perfectly, and I saw where I went wrong.
Your second code made me jump, this actually works, and will be awesome.
I have an issue however because the button of the slider alone is on the top, and the slider in the center.
I tried to fix it by first adding a relative layout, like you did in your first code, but still without success after a lot of hours. Would you be so kind to post an example, so that on this relative other objects can be added?

1 Like

Are you suing the first or the second code? You should create a linear layout (One of the options anyways) and lay your components there. You can try checking for LinerLayout in the old forum and work from those examples. If you are stuck, post your code.

Kf

1 Like

@kfrajer OK, I will work on this, but in the meantime, just to complete my project I will use the first code. My problem now is to dismiss the slider, but using

seekBar.setVisibility(View.GONE);

is not working. Shouldn’t it?

Check this: https://forum.processing.org/two/discussion/26349/android-input-box

Kf

1 Like

@kfrajer I added the below to the code, bu it gives me the error

seekBar.setVisibility(View.GONE);
View cannot be resolved

Code:

void mousePressed() {
  if (mouseY > height/2) {
    act.runOnUiThread(
      new Runnable() {
      public void run() {
        seekBar.setVisibility(View.GONE);
      }
    }
    );
  }
}


Changing

seekBar.setVisibility(View.GONE);

with

fl.removeView(seekBar);

in the mouusepressed() function above does not give any error but also does not remove the view.

You need to add import android.view.View;

Kf

1 Like

Thanks, of course :dizzy_face:

@kfrajer Still in trouble, using seekBar.setVisibility(View.GONE); will compile, but crash as soon as tapped. Using fl.setVisibility(View.GONE); in the runable will remove the FrameLayout, and a blank screen appears. The draw() function does not function anymore.

@kfrajer
seekBar.setVisibility(View.GONE); will work properly whenever and wherever you put it in the code between initialzation of the SeekBar and the end of the onStart.
However using it in the mousePressed function will lett the program crash. Any idea where to start to solve this problem??

Is seekBar defined in the global scope?

Here is an example using buttons, textView, seekBar, Color, resources (ids and strings) and LinerLayout.

Need to consider that for this test the name of my temporal sketch was sketch_180627b . This is important as you will need to change this to the name of your sketch in the code below. This will allow you to access resources defined as XML. Folder structure and files shown below.

Kf

C:\Users\C\AppData\Local\Temp\untitled3773019319882703841sketches>tree /f
Folder PATH listing for volume Windows8_OS
Volume serial number is 4E33-E988
C:.
└───sketch_180627b
    │   AndroidManifest.xml
    │   AppLifeCycle.pde
    │   sketch.properties
    │   sketch_180627b.pde
    │
    ├───code
    │       sketch.properties
    │
    └───res
        └───values
                ids.xml
                strings.xml

FILE: ids.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item type="id" name="button_text_change" />
</resources>

FILE: strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="string_button_text_change">Random Msg!</string>
</resources>

FILE: sketch_180627b.pde

//REFERENCE: https://discourse.processing.org/t/android-seekbar-slider/1245/2
//REFERENCE: https://forum.processing.org/two/discussion/26349/android-input-box
//REFERENCE: https://forum.processing.org/two/discussion/26515/scrollable-image-with-scrollview


import android.support.v7.app.AppCompatActivity;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.app.Activity;
import android.content.Context;
import android.widget.FrameLayout;
import android.widget.Toast;
import android.os.Looper;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.os.Bundle;

import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.R;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.LinearLayout;
import android.graphics.Color;

import processing.android.CompatUtils;


final String MSGS[]={"Today is fun", "Yesterday is sunny", "Tomorrow is a new day", "See you soon", "Hey, what's up?"};
final int UNKNOWN_ID=-1;
final color BGCOLOR=color(10, 10, 250);
final int MAX_ALPHA=256;
final int MAX_RED=256;

Activity act;
Context mC;
FrameLayout fl;
//SeekBar seekBar;

int tvId=UNKNOWN_ID;
int btTvId=UNKNOWN_ID;
int btToastId=UNKNOWN_ID;
int btSliderId=UNKNOWN_ID;
int sliderId=UNKNOWN_ID;

color beginLGcolor=color(255, 0, 0, 255);
color endLGcolor=color(255, 0, 0, 0);
float cProgressValueNorm=0;

void settings() {

  size(displayWidth, displayHeight>>1, P2D);
}



void draw() {
  background(BGCOLOR);
  rectLinearGradient(width*0.25, height*0.25, width*0.75, height*0.75, beginLGcolor, endLGcolor);
}

void rectLinearGradient(float x0, float y0, float x1, float y1, color c1, color c2) {

  if (x0>x1) {
    println("Nothing done as x0, x1 are not valid");
    return;
  }

  if (y0>y1) {
    println("Nothing done as y0, y1 are not valid");
    return;
  }

  pushStyle();
  strokeWeight(1);
  float deltaRow=y1-y0;
  for (float row=y0; row<y1; row++) {
    stroke(lerpColor(c1, c2, (row-y0)/deltaRow));
    line(x0, row, x1, row);
  }
  popStyle();
}

void mouseReleased() {
  println(tvId, btTvId, btToastId, btSliderId, sliderId);
}

@ Override 
  public void onStart() {

  super.onStart();

  act = this.getActivity();
  mC= act.getApplicationContext();
  // OOOOOOOOOOOOOOOO---------------------------OOOOOOOOOOOOOOOO

  // OOOOOOOOOOOOOOOO---------------------------OOOOOOOOOOOOOOOO

  act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

  TextView tv = new TextView(this.getActivity());
  tv.setTextSize(24);
  tv.setTextColor(Color.rgb(20, 0, 0));
  tv.setText ("No message yet!");  
  tv.setGravity(Gravity.RIGHT);
  tvId=CompatUtils.getUniqueViewId();
  tv.setId(tvId);


  Button textSwitchButton= new Button(act);
  textSwitchButton.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 
    RelativeLayout.LayoutParams.WRAP_CONTENT));
  textSwitchButton.setTextSize(10);
  textSwitchButton.setText (processing.test.sketch_180627b.R.string.string_button_text_change);  //https://developer.android.com/guide/topics/resources/string-resource#String
  btTvId=processing.test.sketch_180627b.R.id.button_text_change; //CompatUtils.getUniqueViewId();      //com.example.sketch_180627b.
  textSwitchButton.setId(btTvId);
  textSwitchButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View V) {

      //Code here
      act.runOnUiThread(
        new Runnable() {
        public void run() {

          TextView tvx = (TextView)act.findViewById(tvId);   
          if (tvx!=null) {
            String msg=MSGS[int(random(MSGS.length))];
            tvx.setText(msg);
          } else {
            println("TV view was not found!");
          }
        }
      }
      );
    }
  }
  );


  Button toastButton= new Button(act);
  //https://stackoverflow.com/questions/5191099/how-to-set-relativelayout-layout-params-in-code-not-in-xml
  RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
    RelativeLayout.LayoutParams.WRAP_CONTENT); 
  toastButton.setLayoutParams(params);
  //toastButton.setGravity(Gravity.CENTER_HORIZONTAL);
  toastButton.setTextSize(10);
  toastButton.setText ("Toast!");
  btToastId=CompatUtils.getUniqueViewId();
  toastButton.setId(btToastId);
  toastButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View V) {

      //Code here
      Toast.makeText(mC, "Hello World!", Toast.LENGTH_SHORT).show();
    }
  }
  );

  Button sliderControlButton= new Button(act);
  sliderControlButton.setTextSize(10);
  sliderControlButton.setTextColor(Color.rgb(0, 0, 0));
  sliderControlButton.setText ("Toggle Slider");
  //sliderControlButton.setX(width*0.60);
  //sliderControlButton.setY(200);
  btSliderId=CompatUtils.getUniqueViewId();
  sliderControlButton.setId(btSliderId);
  sliderControlButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View V) {

      //Code here
      act.runOnUiThread(
        new Runnable() {
        public void run() {
          SeekBar bar = (SeekBar)act.findViewById(sliderId);
          if (bar!=null) {

            if (bar.getVisibility()!=View.VISIBLE)bar.setVisibility(View.VISIBLE);            
            else bar.setVisibility(View.INVISIBLE);
          } else {
            println("Slider view was not found!");
          }
        }
      }
      );
    }
  }
  );

  SeekBar seekBar = new SeekBar(mC);
  //seekBar.setLayoutParams (
  //  new RelativeLayout.LayoutParams (
  //  RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT
  //  )
  //  );  
  seekBar.setPadding(100, 100, 200, 0);
  sliderId=CompatUtils.getUniqueViewId();
  seekBar.setId(sliderId);
  seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    @Override
      public void onStartTrackingTouch(SeekBar seekBar) {
      ;
    }
    @Override
      public void onStopTrackingTouch(SeekBar seekBar) {

      //Value compute on onProgressChanged()
      act.runOnUiThread(
        new Runnable() {
        public void run() {

          Button but = (Button)act.findViewById(btSliderId);   
          if (but!=null) {
            but.setTextColor(Color.rgb(cProgressValueNorm*MAX_RED, 0, 0));
          }
        }
      }
      );
    }
    @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      println(progress, seekBar.getMax());
      cProgressValueNorm = progress/float(seekBar.getMax());
      float aFactor=cProgressValueNorm * MAX_ALPHA;
      endLGcolor=color(255, 0, 0, aFactor);
    }
  }
  );

  LinearLayout layoutContainer=new LinearLayout(act);
  layoutContainer.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 
  layoutContainer.setOrientation(LinearLayout.VERTICAL);  
  layoutContainer.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
  layoutContainer.addView(tv);
  layoutContainer.addView(textSwitchButton);
  layoutContainer.addView(toastButton, params);
  layoutContainer.addView(sliderControlButton);
  layoutContainer.addView(seekBar);


  fl = (FrameLayout)act.findViewById(R.id.content);
  fl.addView(layoutContainer);
}

1 Like

Awesome !! This clarifies a whole lot. It is a good thing that you only can give a like once, otherwise I would hurt my finger :smiley:.
The only minor change I had to make was making the color’s red component an integer like : but.setTextColor(Color.rgb(int(cProgressValueNorm*MAX_RED), 0, 0));
Below is a code for an vertical SeekBar. I found a trick by playing around. There sure will a proper way but this what I found out. When you rotate the seekBar 90° It will turn around it’s right upper corner and will become invisible. However when you do 1 pixel padding on the FrameLayout and paint it’s background, the SeekBar becomes visible again. Just don’t ask me why :grin:.
Once again thank you very much for all the help.

import android.view.ViewGroup; 
import android.widget.SeekBar; 
import android.app.Activity; 
import android.content.Context; 
import android.widget.RelativeLayout;
import android.widget.FrameLayout;
import android.view.WindowManager; 
import android.view.inputmethod.InputMethodManager; 
import android.view.View;
import android.view.ViewGroup.LayoutParams; 
import android.R;


Activity act; 
Context mC; 
FrameLayout fl; 
SeekBar seekBar;
int pgr;
int seekBarWidth = 500;

void settings() { 
  size(displayWidth, displayHeight);
}

void setup() {
  textSize(32);
}

void draw() { 
  background(50, 37, 115);
  text(pgr, width/2, height/2);
}

@ Override public void onStart() { 
  super.onStart(); 
  act = this.getActivity(); 
  mC= act.getApplicationContext(); 
  act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 

  SeekBar seekBar = new SeekBar(mC); 
  seekBar.setLayoutParams ( new RelativeLayout.LayoutParams ( seekBarWidth, LayoutParams.WRAP_CONTENT ) ); 
  seekBar.setX(width/2);
  seekBar.setY(height/2);
  seekBar.setRotation(90);
  seekBar.setMax(250);
  seekBar.setProgress(50);
  // seekBar.setBackgroundColor(Color.RED);  

  fl = (FrameLayout)act.findViewById(R.id.content); 
  fl.addView(seekBar); 
  fl.setBackgroundColor(#321173 ); // YOUR BACKGROUND COLOR
  fl.setPadding(1, 1, 1, 1);

  seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
    @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onStopTrackingTouch(SeekBar seekBar) {
    } 
    @Override 
      public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) { 
      pgr = progress;
    }
  } 
  );
}
1 Like

@kfrajer In your code you setted the button text color in the onStopTrackingTouch() function.
I want to pass the progress value to the TextView by the code below, but the seekBarValue always is null. Where am I wrong? (no errors in console).

seekBar.setOnSeekBarChangeListener(
    new SeekBar.OnSeekBarChangeListener() { 
    @Override 
      public void onStartTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onStopTrackingTouch(SeekBar seekBar) {
    }
    @Override 
      public void onProgressChanged (SeekBar seekBar, final int progress, boolean fromUser) {
      act.runOnUiThread( new Runnable() { 
        public void run() { 
          TextView seekBarValue = (TextView)act.findViewById(tvId);
          //    Button but = (Button)act.findViewById(btSliderId); 
          println(seekBarValue)
          if (seekBarValue != null) { 
          //   but.setTextColor(Color.rgb(cProgressValueNorm*MAX_RED, 0, 0));
            seekBarValue.setText(String.valueOf(progress));
          }
        }
      }
      );
    }
  }
  );

Solved! I forgot to se the Layout params.:smiling_imp:

@kfrajer In your template code I want to start with the seekBar unvisable so i added the line

seebBar.setVisibility(View.INVISIBLE);

below the line

seekBar.setId(sliderId);

And this really starts the sketch with the slider ‘off screen’. But then the toggle button will not toggle anymore!
I want to start my sketch empty and, with a mouseclick, let the slider showing up. I,ve also tried

SeekBar bar = (SeekBar)act.findViewById(sliderId);
if (bar.getVisibility()!=View.VISIBLE)
bar.setVisibility(View.VISIBLE);

without success and all kind of other things but nothing worked out.
How to do this?

I found a solution by not setting

seebBar.setVisibility(View.INVISIBLE);

in the onStart(), but setting

 act.runOnUiThread( new Runnable() { 
      public void run() { 
        SeekBar bar = (SeekBar)act.findViewById(sliderId);
        bar.setVisibility(View.INVISIBLE);
      }
    }
    );

in the setup()
The problem is however, when running the program the bar will show up for a second before it becomes invisible.
I really would like to know how to this properly ( the correct way).

I would need to setup the Android project to test it. I can’t atm. I can suggest you try to call this onResume(). are you adding this dynamically in onCreate()? Could you set the visibility state there? [I read your post above] try setting the visibility after you added to the view in onCreate(). I am not sure if this would work but it is worth to try. Lastly, You should check the life cycle of a fragment as it provides other points in your fragment life cycle where you could update the view and its elements. However, I think my first proposed method should work aka. performing this update in the onResume() call.

Kf