android - 更改搜索栏时不调用 onProgressChanged 方法?

标签 android android-seekbar

这是我使用的代码:

import android.support.v4.app.Fragment; 
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;

/**
 * Created by Arsalan on 8/29/2016.
 */
public class ToolbarFragmnet extends Fragment implements        
SeekBar.OnSeekBarChangeListener {

    @Nullable
    private  static int s=10;
    private  static EditText editText;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,     Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.toolbar_fragment, container, false);
        editText = (EditText) view.findViewById(R.id.edittext1);
        final SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekBar1);
        final Button button = (Button) view.findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                buttonClicked(view);
            }
        });
        return view;
    }

    ToolbarListner callBackActivity;
    public interface ToolbarListner {
        public void onButtonClick(int position, String text);
    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        try {
            callBackActivity = (ToolbarListner) context;
        } catch (ClassCastException c) {
            throw new ClassCastException(context.toString() + "must be implement");
        }
    }

    private void buttonClicked(View view) {

        callBackActivity.onButtonClick(s,editText.getText().toString());

    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
        s= i
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
}

最佳答案

除非您将listener 设置为seekbar

,否则它永远不会被调用

把他放在onCreateView()方法中

seekBar.setOnSeekBarChangeListener(this);

关于android - 更改搜索栏时不调用 onProgressChanged 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39244694/

相关文章:

android - 在 ViewPager 中输入动画

android - 如何将页脚菜单停靠在 Appcelerator Titanium 的底部?

android - 焦点迷失在 adapter.notifyArrayItemRangeChanged 上

android - 更流畅的 Android SeekBar

android - SeekBar 拇指(9 补丁)无法识别

android - 从 Android 调用 Google Cloud Endpoints API 时出现错误 413(请求实体太大)

Android:调整 Horizo​​ntalScrollView 的大小

Android 媒体播放器搜索栏

Android - 如何更改默认 SeekBar 厚度?

android - 如何制作自定义 SeekBar 以在栏中显示颜色渐变?