下面列出了android.widget.CompoundButton#setText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void set(int elementNum, String stringPart, Image imagePart) {
synchronized (selected) {
strings.set(elementNum, stringPart);
images.set(elementNum, imagePart);
if (buttongroup != null) {
CompoundButton button = buttons.get(elementNum);
button.setText(stringPart);
if (imagePart != null) {
button.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(imagePart.getBitmap()), null, null, null);
} else {
button.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
}
button.setCompoundDrawablePadding(button.getPaddingLeft());
} else if (adapter != null) {
adapter.set(elementNum, stringPart, imagePart);
}
}
}
private void addButton(CompoundButton button, int index, String stringPart, Image imagePart, boolean checked) {
button.setText(stringPart);
if (imagePart != null) {
button.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(imagePart.getBitmap()), null, null, null);
}
button.setCompoundDrawablePadding(button.getPaddingLeft());
button.setId(index);
button.setChecked(checked);
button.setOnCheckedChangeListener(checklistener);
if (index == buttons.size()) {
buttons.add(button);
} else {
buttons.add(index++, button);
if (buttons.get(index).getId() != index) {
updateButtonIDs(index);
}
}
buttongroup.addView(button);
}
/**
*
* @param compoundButton changes the text of the given {@link CompoundButton}
* according if it's "on" or "off"
*/
public void setTextAccordingToState(CompoundButton compoundButton)
{
if(compoundButton.isChecked())
{
compoundButton.setText(onText);
}
else if(compoundButton.isChecked() == false)
{
compoundButton.setText(offText);
}
}