java - 如何确定哪个 android 小部件正在调用我的函数?

标签 java android resources seekbar

我在一个 Android 应用程序中有几个 SeekBar,它们实际上做同样的事情(设置低音、高音、音量)。为了节省为每个 SeekBarOnSeekBarChangeListener 键入新的本地类,我尝试创建一个类,在其 onStopTrackingTouch 中确定正在调用哪个小部件它,并采取适当的行动。

public class mySeekBar implements SeekBar.OnSeekBarChangeListener {
    int progressChanged = 0;

    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
        progressChanged = progress;
    }

    public void onStartTrackingTouch(SeekBar seekBar) {}

    public void onStopTrackingTouch(SeekBar seekBar) {
          // i want a case statement here switched on the widget ID/name, so 
          // i can set the appropriate string s (bass, treble, volume)
        String s = "set_treble " + progressChanged;
        client.sendMessage(s);
    }

}

我如何确定哪个小部件正在调用 onStopTrackingTouch?还是有更清洁或更好的方法来做到这一点?

最佳答案

100%你可以这样判断;

public void onStopTrackingTouch(SeekBar seekBar) {
          // i want a case statement here switched on the widget ID/name, so 
          // i can set the appropriate string s (bass, treble, volume)
        String s = "set_treble " + progressChanged;
        client.sendMessage(s);

       switch (seekBar.getId()) {
                case R.id.seekVolume:

                    break;
                case R.id.bass:
                    break;
                case R.id.trouble:
                    break;
                default:
                    break;
                }
    }

关于java - 如何确定哪个 android 小部件正在调用我的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18415556/

相关文章:

java - Maven - 在依赖项中使用版本

java - 如何相对访问包资源

java - 哪些库已移植到不同的编程语言?

c# - 将数据从 java 应用程序传输到 c#

源自 OpenSSLSocketImpl(而非 SSLSocket)的 Android 自定义套接字

android - 两部安卓手机可以互通吗?

android - flutter : How to prevent rebuild of whole Reorderable Listview?

java - 在 @Source ("../../war/example.txt") textresource 客户端 bundle gwt 中提供外部文件路径

c# - 是否可以将 <Window.Resources> 移动到单独的文件?

java - HttpSessionListener.sessionCreated() 在 Spring MVC 应用程序启动时被调用两次