简体   繁体   English

Android Studio 中的搜索栏

[英]Seekbar in Android Studio

I came across a piece of code,now I am stuck with it.我遇到了一段代码,现在我被它困住了。

        SeekBar volumeControl=(SeekBar)findViewById(R.id.volumeSeekBar);
        volumeControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,progress,0 );


            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

Here I know that volumeControl is a variable of type SeekBar.这里我知道volumeControl是 SeekBar 类型的变量。 In the second line of code volume control is set with a function setOnSeekBarChangeListener .在第二行代码中,音量控制是用函数setOnSeekBarChangeListener设置的。 I am unable to understand what's written inside the brackets of setOnSeekBarChangeListener .我无法理解setOnSeekBarChangeListener括号内的setOnSeekBarChangeListener Can anyone please explain it in detail.谁能详细解释一下。 I am just introduced to java and don't have much knowledge我刚接触java,知识不多

This is a small piece of code to control volume using a seek bar.这是使用搜索栏控制音量的一小段代码。 Inside the brackets of onSeekBarChangeListener , we declare a new SeekBar.onSeekBarChangeListener which implements three methods :onSeekBarChangeListener的括号内,我们声明了一个新的SeekBar.onSeekBarChangeListener ,它实现了三个方法:

  1. onProgressChanged : This basically tracks the change in the seek bar and then sets the volume according to the amount of change. onProgressChanged :这基本上是跟踪搜索栏的变化,然后根据变化量设置音量。

  2. onStartTrackingTouch : This methods contains the code which should be executed when the touch gesture starts. onStartTrackingTouch :此方法包含应在触摸手势开始时执行的代码。

  3. onStopTrackingTouch : This method contains the code which should be executed which the touch gesture stops. onStopTrackingTouch :此方法包含应执行的触摸手势停止的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM