Search code examples
androidincrementseekbar

show progress of seekbar in feet, inches and quarter inch


I am wanting to have a seekbar that when the user slides the thumb pad it adds/subtracts by quarter inch increments. It would need to start at 0'-0.0" and go up to 20'-0.0" I am new to programming and what I have found is that the seekbar only accepts "int" and not double (which is what I need). So would I need to create and array with every individual value and then get the results of the progress bar and then pull that number from my array to display in a textView or is there a way to have the progress bar increment up by quarter inches?

Thanks for your time


Solution

  • Since I did not get a response for another solution other than what I stated in my question here is how I coded it in case someone else might need to know.

    ArrayList<String> arrayListName = new ArrayList<String>();    
    for (int i = 0; i < 20; i++) {
            for (int ii = 0; ii < 12; ii++) {
                for (int iii = 0; iii < 4; iii++) {
                    arrayListName.add(i + "'-" + ii + "." + iii + '"');
                } // end nested loop iii
            } // end nested loop ii
        } // end nested loop i
        String twenty = "20'-0.0\"";
        arrayListName.add(twenty);
        int lengthOfArrayListName = arrayListName.size(); 
    

    The above code generates an array with 960 elements in it. I then used the next line to set the max for the progress bar

    seekBarName.setMax(lengthOfArrayListName - 1);
    

    you need to subtract 1 from the length because the array starts a 0 not 1 or you will get an arrayoutofbounds FC

    next in the onProgressChanged for the SeekBar I used this line to use the position value of the seekbar to then set the text of a textView from the arrayListName.

    textViewName.setText(arrayListName.get(progress));
    

    This method works just fine except that with such a large number set to choose from the user may (most likely will not be able to) stop the thumb button right on the number they want. So I added a "+" and "-" button under the seekbar that increments the progress by 1.