how to use only one listener for multiple sliders (android)?
how to use only one listener for multiple sliders (android)?
I want to use this Fluid slider in my android app and I want 5 of these
if I add different listeners for all 5 then code will become very big. Please take a look and see if multiple sliders can make use of only one setPositionListner method using switch case or any other way.
Below is the code for one fluid slider. First 2 methods is used to hide the text behind and again reveal it and last one is used to find the current position of the slider.
public class MainActivity extends AppCompatActivity
@SuppressWarnings("Convert2Lambda")
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView textView = findViewById(R.id.textView);
final int max = 45;
final int min = 10;
final int total = max - min;
final FluidSlider slider = findViewById(R.id.fluidSlider);
slider.setBeginTrackingListener(new Function0<Unit>()
@Override
public Unit invoke()
textView.setVisibility(View.INVISIBLE);
return Unit.INSTANCE;
);
slider.setEndTrackingListener(new Function0<Unit>()
@Override
public Unit invoke()
textView.setVisibility(View.VISIBLE);
return Unit.INSTANCE;
);
// Java 8 lambda
slider.setPositionListener(pos ->
final String value = String.valueOf( (int)(min + total * pos) );
slider.setBubbleText(value);
return Unit.INSTANCE;
);
slider.setPosition(0.3f);
slider.setStartText(String.valueOf(min));
slider.setEndText(String.valueOf(max));
I want to use 5 sliders in my app but dont want to add individual slider.setPositionListner for each one of them. Like in case of 5 buttons we can use only one onClickListner and use switch case to select action for different buttons
– 10feetPole
Sep 4 '18 at 13:52
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
can't understand your requirement
– Ravi Makvana
Sep 4 '18 at 11:26