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));






can't understand your requirement
– Ravi Makvana
Sep 4 '18 at 11:26





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế