1
Я следую руководству по адресу this site, чтобы реализовать пользовательское состояние для списка состояний. Он работает с логическими атрибутами, но не со строковыми атрибутами.Android - Пользовательские состояния со строковым значением
Это мой исходный код:
Государственно-лист:
Атрибуты:
<declare-styleable name="CategoryIconView"> <attr name="category_id" format="string"/> </declare-styleable>
на заказ Вид:
public class CategoryIconView extends ImageView { // this is used when we want to merge our state with the ones from the system private static final int[] CATEGORY_ID_STATE_SET = {R.attr.category_id}; String categoryID; public CategoryIconView(Context context) { super(context); } public CategoryIconView(Context context, AttributeSet attrs) { super(context, attrs); } public CategoryIconView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public int[] onCreateDrawableState(int extraSpace) { LogUtils.d(getClass().getSimpleName(), "category ID " + categoryID); final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); if (categoryID != null) { mergeDrawableStates(drawableState, CATEGORY_ID_STATE_SET); } return drawableState; } // this method will be used when you will need to set your image button state in the code public void setCategoryID(String categoryId){ this.categoryID = "Three"; refreshDrawableState(); } }
Вы можете просто правильно форматировать код ? –
Извините. Я не знаю, почему я не могу отформатировать код с помощью SO-редактора. Я использую firefox. –
Здравствуйте, я дал какой-то ответ, можете ли вы это проверить? После проверки сообщите мне. –