我需要在同一Java类中创建多个搜索栏。但是,我想知道是否需要为每个搜索栏设置每个setOnSeekBarChangeListener吗?如果这样做,代码似乎太长(我需要在同一类中创建10个搜索栏)。还有其他可以缩短代码的解决方案吗?非常感谢您的帮助。 :)
下面是我的代码
class String
def character_count
uppercase_count = 0
lowercase_count = 0
digit_count = 0
uppercase_range = Range.new('A', 'Z')
lowercase_range = Range.new('a', 'z')
digit_range = Range.new('0', '9')
special_character_count = 0
each_char do |item|
case item
when uppercase_range
uppercase_count += 1
when lowercase_range
lowercase_count += 1
when digit_range
digit_count += 1
else
special_character_count += 1
end
end
[lowercase_count, uppercase_count, digit_count, special_character_count]
end
end
if ARGV.empty?
puts 'Please provide an input'
else
string = ARGV[0]
count_array = string.character_count
puts "Lowercase characters = #{count_array[0]}"
puts "Uppercase characters = #{count_array[1]}"
puts "Numeric characters = #{count_array[2]}"
puts "Special characters = #{count_array[3]}"
end
答案 0 :(得分:0)
按照以下步骤很简单
仅在类/片段中实现SeekBar.OnSeekBarChangeListener
public class Home extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
}
您不必为每个Seekbar编写新的OnSeekBarChangeListener ...
只需实施
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
} to your Activity/Fragment..
现在您可以检查ID并根据其执行操作