Reputation:
Im trying to build an application on my own with a multi-state toggle button and I want to check which state is selected.
Is there any method or something like that to check this?
I want to say that in simple toggles there's the method " isChecked(); ". Note that i got 3 states inside the toggle.
1.Lowercase
2.Uppercase
3.Both
Upvotes: 0
Views: 794
Reputation: 543
Just try to implement above things using jlhonora MultistateToggle Library
getValue() is the method which returns index number so that you can easily identify what user has selected
public class AddListingForm extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_listing_form);
final MultiStateToggleButton toggleButton= (MultiStateToggleButton)
this.findViewById(R.id.MSTB);
// With an array
CharSequence[] states= new CharSequence[]{"Lowercase","Uppercase",
"Both"};
toggleButton.setElements(states);
toggleButton.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() {
@Override
public void onValueChanged(int position) {
property_type = states[position].toString();
}
});
int a=toggleButton.getValue();
// if User selected Lowercase then you will get value of a is 0
// Similarly for Uppercase a will be 1 and for Both a will be 2
}
}
Upvotes: 0