Is it possible to have a switch widget for ICS versions, but a checkbox for pre ICS? If so, how?
I’m not worried about other components, only switch.
MY SOLUTION
Seeing as switch and checkbox both inherit from CompoundButton, I just did this
((CompoundButton)findViewById(R.id.swTax)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
calculateValues();
}
});
Create a separate layout XML file for ICS versions by placing it in a separate layout folder, e.g.
layout-v14. To prevent a lot of duplicate XML, use one main layout file and include the widget. The resulting file structure would look something like this:In
mylayout.xmlyou would have something like:In the
Activityfor this layout you will have to check the version as well before setting up any interaction with either theCheckBoxorSwitchwidget: