1. <legend id='ehiYX'><style id='ehiYX'><dir id='ehiYX'><q id='ehiYX'></q></dir></style></legend>
  2. <tfoot id='ehiYX'></tfoot>

    <small id='ehiYX'></small><noframes id='ehiYX'>

    1. <i id='ehiYX'><tr id='ehiYX'><dt id='ehiYX'><q id='ehiYX'><span id='ehiYX'><b id='ehiYX'><form id='ehiYX'><ins id='ehiYX'></ins><ul id='ehiYX'></ul><sub id='ehiYX'></sub></form><legend id='ehiYX'></legend><bdo id='ehiYX'><pre id='ehiYX'><center id='ehiYX'></center></pre></bdo></b><th id='ehiYX'></th></span></q></dt></tr></i><div id='ehiYX'><tfoot id='ehiYX'></tfoot><dl id='ehiYX'><fieldset id='ehiYX'></fieldset></dl></div>

      • <bdo id='ehiYX'></bdo><ul id='ehiYX'></ul>

      根据 EditText 值更改 SeekBar 进度

      Change SeekBar progress based on EditText value(根据 EditText 值更改 SeekBar 进度)
      <tfoot id='Ic0sO'></tfoot>

          <tbody id='Ic0sO'></tbody>
      1. <small id='Ic0sO'></small><noframes id='Ic0sO'>

        1. <i id='Ic0sO'><tr id='Ic0sO'><dt id='Ic0sO'><q id='Ic0sO'><span id='Ic0sO'><b id='Ic0sO'><form id='Ic0sO'><ins id='Ic0sO'></ins><ul id='Ic0sO'></ul><sub id='Ic0sO'></sub></form><legend id='Ic0sO'></legend><bdo id='Ic0sO'><pre id='Ic0sO'><center id='Ic0sO'></center></pre></bdo></b><th id='Ic0sO'></th></span></q></dt></tr></i><div id='Ic0sO'><tfoot id='Ic0sO'></tfoot><dl id='Ic0sO'><fieldset id='Ic0sO'></fieldset></dl></div>
        2. <legend id='Ic0sO'><style id='Ic0sO'><dir id='Ic0sO'><q id='Ic0sO'></q></dir></style></legend>
              <bdo id='Ic0sO'></bdo><ul id='Ic0sO'></ul>

              • 本文介绍了根据 EditText 值更改 SeekBar 进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试根据在 EditText 中输入的数字来更改 SeekBar 的进度,但由于某种原因 EditText 值变为到最大,我无法在 SeekBar 中滑动拇指.

                I am trying to change the progress of a SeekBar based on the number entered in an EditText but for some reason the EditText value goes to the max and I can't slide the thumb in the SeekBar.

                我希望实现的目标:如果在 EditText 中输入的值介于 70 和 190 之间(包括两个数字),则将 SeekBar 的进度更改为该值.

                What I am looking to achieve: If the value entered in the EditText anywhere between 70 and 190 (including both number) change the progress of the SeekBar to that value.

                部分 Java 代码:

                Partial Java code:

                etOne = (EditText) findViewById(R.id.etSyst);
                        etOne.addTextChangedListener(new TextWatcher() {
                            public void afterTextChanged(Editable s) {
                                String filtered_str = s.toString();
                                if (Integer.parseInt(filtered_str) >= 70 && Integer.parseInt(filtered_str) <= 190) {
                                    sbSyst.setProgress(Integer.parseInt(filtered_str));
                                }
                            }
                            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
                
                            public void onTextChanged(CharSequence s, int start, int before, int count) {}
                        });
                

                部分 XML:

                <SeekBar
                            android:id="@+id/syst_bar"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="10dp"
                            android:progress="0"
                            android:max="120"
                            android:progressDrawable="@drawable/progress_bar"
                            android:secondaryProgress="0"
                            android:thumb="@drawable/thumb_state" />
                

                我给每个值加 70,因为 SeekBar 从 0 开始,但我希望它从 70 开始.

                I add 70 to each value, because SeekBar starts at 0, but I want it to start at 70.

                使用上面的代码后是这样的:

                After using the above code, this is what it looks like:

                SeekBar 是最大数,EditText 也是最大数.

                The SeekBar is at the maximum number and the EditText is at the maximum as well.

                推荐答案

                etOne = (EditText) findViewById(R.id.etSyst);
                        etOne.addTextChangedListener(new TextWatcher() {
                            public void afterTextChanged(Editable s) {
                                int i = Integer.parseInt(s.toString());
                                if (i >= 70 && i <= 190) {
                                    sbSyst.setProgress( i - 70); // This ensures 0-120 value for seekbar
                                }
                            }
                            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
                
                            public void onTextChanged(CharSequence s, int start, int before, int count) {}
                        });
                

                这篇关于根据 EditText 值更改 SeekBar 进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                How to convert Integer to int?(如何将整数转换为整数?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                Inconsistent behavior on java#39;s ==(java的行为不一致==)
                Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)
                  <i id='CJlzA'><tr id='CJlzA'><dt id='CJlzA'><q id='CJlzA'><span id='CJlzA'><b id='CJlzA'><form id='CJlzA'><ins id='CJlzA'></ins><ul id='CJlzA'></ul><sub id='CJlzA'></sub></form><legend id='CJlzA'></legend><bdo id='CJlzA'><pre id='CJlzA'><center id='CJlzA'></center></pre></bdo></b><th id='CJlzA'></th></span></q></dt></tr></i><div id='CJlzA'><tfoot id='CJlzA'></tfoot><dl id='CJlzA'><fieldset id='CJlzA'></fieldset></dl></div>

                • <small id='CJlzA'></small><noframes id='CJlzA'>

                      <tbody id='CJlzA'></tbody>
                    • <bdo id='CJlzA'></bdo><ul id='CJlzA'></ul>
                      <tfoot id='CJlzA'></tfoot>
                      <legend id='CJlzA'><style id='CJlzA'><dir id='CJlzA'><q id='CJlzA'></q></dir></style></legend>