SeekBar 在另一个里面 class
SeekBar inside another class
我创建了一个显示距离的 SeekBar。此距离用于显示以特定距离为半径的圆。
在我的 onCreate
中有以下几行:
SeekBar seekBar = findViewById(R.id.sb_radius);
seekBar.setOnSeekBarChangeListener(seekBarChangeListener);
那么,我使用的class如下:
private void Search_Map(float dpWidth, float dpHeight, Object Lat, Object Lon) {
SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// updated continuously as the user slides the thumb
tvDistance.setText( "Progress: " + progress );
Show_Map(dpWidth, dpHeight, Lat, Lon, progress*1000);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// called when the user first touches the SeekBar
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// called after the user finishes moving the SeekBar
}
};
}
我的问题是它从不执行任何操作,因为我在 onCreate
中收到错误消息:
cannot resolve symbol seekBarChangeListener.
如何在我的 class 中使用搜索栏并使侦听器正常工作?
谢谢
从 onCreate
中删除 seekBar.setOnSeekBarChangeListener(seekBarChangeListener);
行并将其添加到 Search_Map
的末尾
class ClassName{
Seekerbar seekerbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_name);
seekBar = findViewById(R.id.sb_radius);
}
private void Search_Map(float dpWidth, float dpHeight, Object Lat, Object Lon) {
SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// updated continuously as the user slides the thumb
tvDistance.setText( "Progress: " + progress );
Show_Map(dpWidth, dpHeight, Lat, Lon, progress*1000);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// called when the user first touches the SeekBar
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// called after the user finishes moving the SeekBar
}
};
seekBar.setOnSeekBarChangeListener(seekBarChangeListener);
}
}
我创建了一个显示距离的 SeekBar。此距离用于显示以特定距离为半径的圆。
在我的 onCreate
中有以下几行:
SeekBar seekBar = findViewById(R.id.sb_radius);
seekBar.setOnSeekBarChangeListener(seekBarChangeListener);
那么,我使用的class如下:
private void Search_Map(float dpWidth, float dpHeight, Object Lat, Object Lon) {
SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// updated continuously as the user slides the thumb
tvDistance.setText( "Progress: " + progress );
Show_Map(dpWidth, dpHeight, Lat, Lon, progress*1000);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// called when the user first touches the SeekBar
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// called after the user finishes moving the SeekBar
}
};
}
我的问题是它从不执行任何操作,因为我在 onCreate
中收到错误消息:
cannot resolve symbol seekBarChangeListener.
如何在我的 class 中使用搜索栏并使侦听器正常工作?
谢谢
从 onCreate
中删除 seekBar.setOnSeekBarChangeListener(seekBarChangeListener);
行并将其添加到 Search_Map
class ClassName{
Seekerbar seekerbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_name);
seekBar = findViewById(R.id.sb_radius);
}
private void Search_Map(float dpWidth, float dpHeight, Object Lat, Object Lon) {
SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// updated continuously as the user slides the thumb
tvDistance.setText( "Progress: " + progress );
Show_Map(dpWidth, dpHeight, Lat, Lon, progress*1000);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// called when the user first touches the SeekBar
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// called after the user finishes moving the SeekBar
}
};
seekBar.setOnSeekBarChangeListener(seekBarChangeListener);
}
}