Skip to content Skip to sidebar Skip to footer

Show Progress Of Seekbar In A Textview Inside A Custom Alert Dialog

I have a custom alert dialog which contains a seekbar and a textview. I want to display progress of seekbar in that textview in percents when the user interacts with the thumb of s

Solution 1:

TextView expects to get charSequence and you pass an int to it. One way to solve this is Integer.toString(progress)


Solution 2:

Instead of putting null as parent add your root layout as parent while inflating the dialog layout as below.

View layoutFromInflater = inflater
                           .inflate(R.layout.dialog_fragment_sensitivity_layout,
                           (ViewGroup) findViewById(R.id.yourLayoutRoot)); 

and find the views by layoutFromInflater only.

Hope this should work fine for you.


Solution 3:

Dialog yourDialog = new Dialog(this);
LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.your_dialog,(ViewGroup)findViewById(R.id.your_dialog_root_element));
yourDialog.setContentView(layout);

Thus, you can operate on your element as follows:

TextView yourDialogTextView = (TextView)layout.findViewById(R.id.your_dialog_tv);
SeekBar yourDialogSeekBar = (SeekBar)layout.findViewById(R.id.your_dialog_seekbar);
// ...

and so on, to set listeners for seekbar.

EDIT: The seekbar onchangelistener should be as follows:

OnSeekBarChangeListener yourSeekBarListener = new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
        //add code here
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
        //add code here
}

@Override
public void onProgressChanged(SeekBar seekBark, int progress, boolean fromUser) {
        //add code here
yourDialogTextView.setText(progress);
    }
 };
 yourDialogSeekBar.setOnSeekBarChangeListener(yourSeekBarListener);

Solution 4:

I know this is a pretty old question but it's actually really easy. Just type this

progress_tv.setText("" + progress + "%");

Post a Comment for "Show Progress Of Seekbar In A Textview Inside A Custom Alert Dialog"