如何在android

时间:2015-09-02 13:07:50

标签: java android

如何在android上提供seekbar的数量。 请回答我的问题,因为我需要它。  谢谢 XML:

 <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

爪哇:

public class Setting extends ActionBarActivity implements OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
}
}

3 个答案:

答案 0 :(得分:2)

您可以使用以下网址中的“DiscreteSeekBar”:

https://github.com/AnderWeb/discreteSeekBar

感谢。

答案 1 :(得分:2)

首先,在XML中设置SeekBar的最大值。 将以下属性添加到SekkBar:

    /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package positivenegative;

/**
 *
 * @author
 */
import java.util.Scanner;

public class PositiveNegative {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner input = new Scanner(System.in);

        // Welcome message
        System.out.println("Welcome to the Number Averagererer.");
            // Yes I'm aware "Averagererer" isn't a word
        System.out.println("Be sure to enter a 0 at the end");
        System.out.println("or the program will not work.");
        System.out.print("Enter an integer, the input ends if it is 0: ");

        // Initialize variables
        int number, totalPositive=0, totalNegative=0, counter=0;  
        double average=0;

        // Process the entered variables and sort/calculate them        
        while ((number = input.nextInt()) != 0){ // Continues if number isn't 0
            System.out.println(number); //debugging to see what the nextInt is doing
            // Adds to positive  
            if (number > 0){
                totalPositive++;
                counter++;
                average = (average + number);         
                }
            // Adds to negative
            else{
                System.out.println(number);
                totalNegative++;
                counter++;        
                average = (average + number);
                }
        }

    // Output message if the user only enters "0"
    if (counter == 0){
        System.out.println("No numbers were entered except 0");
        }                    

    // Output message with calculated data from input
    else{
        double total = average;
        average = (average / counter);
        System.out.println("The number of positives is: " + totalPositive);
        System.out.println("The number of negatives is: " + totalNegative);
        System.out.println("The total is: " + total);
        System.out.println("The average is: " + average);
        }
    }
}

然后在代码中:

android:max="40"

getProgress()将返回当前值(从0到40);

但你应该使用监听器进行更改并获得新值:

SeekBar seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
int currentValue = seekBar1.getProgress();

答案 2 :(得分:0)

尝试使用100作为最大搜索次数:

XCUIApplication *app = [[XCUIApplication alloc] init];
app.launchArguments = @[@"--reset-container"];
[app launch];

选择搜索栏,     onProgressChanged在您寻找时提供实时选择更改,但是当您停止然后遇到onProgressStop时,则按您的意愿执行:

      <SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="26dp"
            android:max="100"/>