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
}
}
1条答案
按热度按时间7uzetpgm1#
试着用jlhonora MultistateToggle Library来实现上面的东西
getValue()是返回索引号的方法,这样您就可以轻松地识别用户选择了什么