class MenuAdapter extends ArrayAdapter<CharSequence> { public MenuAdapter( Context context, int textViewResId, CharSequence[] strings) { super(context, textViewResId, strings); } public static MenuAdapter createFromResource( Context context, int textArrayResId, int textViewResId) { Resources resources = context.getResources(); CharSequence[] strings = resources.getTextArray(textArrayResId); return new MenuAdapter(context, textViewResId, strings); } public boolean areAllItemsEnabled() { return false; } public boolean isEnabled(int position) { // return false if position == position you want to disable } }
private static @Nullable Unbinder parseBindArray(Object target, Field field, View source) { BindArray bindArray = field.getAnnotation(BindArray.class); if (bindArray == null) { return null; } validateMember(field); int id = bindArray.value(); Resources resources = source.getContext().getResources(); Object value; Class<?> fieldType = field.getType(); if (fieldType == TypedArray.class) { value = resources.obtainTypedArray(id); } else if (fieldType.isArray()) { Class<?> componentType = fieldType.getComponentType(); if (componentType == String.class) { value = resources.getStringArray(id); } else if (componentType == int.class) { value = resources.getIntArray(id); } else if (componentType == CharSequence.class) { value = resources.getTextArray(id); } else { throw new IllegalStateException(); // TODO } } else { throw new IllegalStateException(); // TODO } trySet(field, target, value); return Unbinder.EMPTY; }
/** * @see #setEntries(CharSequence[]) * @param entriesResId The entries array as a resource. */ public void setEntries(@ArrayRes int entriesResId) { setEntries(getContext().getResources().getTextArray(entriesResId)); }
/** * @see #setEntryValues(CharSequence[]) * @param entryValuesResId The entry values array as a resource. */ public void setEntryValues(@ArrayRes int entryValuesResId) { setEntryValues(getContext().getResources().getTextArray(entryValuesResId)); }
/** * Set a {@linkplain com.prolificinteractive.materialcalendarview.format.TitleFormatter} * using the provided month labels * * @param arrayRes String array resource of month labels to use * @see com.prolificinteractive.materialcalendarview.format.MonthArrayTitleFormatter * @see #setTitleFormatter(com.prolificinteractive.materialcalendarview.format.TitleFormatter) */ public void setTitleMonths(@ArrayRes int arrayRes) { setTitleMonths(getResources().getTextArray(arrayRes)); }
/** * Set a {@linkplain com.prolificinteractive.materialcalendarview.format.WeekDayFormatter} * with the provided week day labels * * @param arrayRes String array resource of week day labels * @see com.prolificinteractive.materialcalendarview.format.ArrayWeekDayFormatter * @see #setWeekDayFormatter(com.prolificinteractive.materialcalendarview.format.WeekDayFormatter) */ public void setWeekDayLabels(@ArrayRes int arrayRes) { setWeekDayLabels(getResources().getTextArray(arrayRes)); }
@Test public void asCharSequenceArray() { CharSequenceArrayTarget target = new CharSequenceArrayTarget(); CharSequence[] expected = context.getResources().getTextArray(R.array.int_one_two_three); Unbinder unbinder = new BindArrayTest$CharSequenceArrayTarget_ViewBinding(target, context); assertThat(target.actual).isEqualTo(expected); unbinder.unbind(); assertThat(target.actual).isEqualTo(expected); } }
widget.setHeaderTextAppearance(R.style.CustomTextAppearance); widget.setDateTextAppearance(R.style.CustomTextAppearance); widget.setTitleFormatter(new MonthArrayTitleFormatter(getResources().getTextArray(R.array.custom_months))); widget.setWeekDayFormatter(new ArrayWeekDayFormatter(getResources().getTextArray(R.array.custom_weekdays))); widget.setTileSize((int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
@Override public CharSequence[] getTextArray(int id) throws NotFoundException { try { return super.getTextArray(id); } catch (NotFoundException e) { return mHostResources.getTextArray(id); } }
public CharSequence[] getTextArray(int res) { CharSequence[] result = new CharSequence[0]; try { result = mContext.getResources().getTextArray(res); } catch (Exception e) { } return result; }
public CharSequence[] getTextArray(int res) { CharSequence[] result = new CharSequence[0]; try { result = mContext.getResources().getTextArray(res); } catch (Exception e) { } return result; }
@Implementation public static ArrayAdapter<CharSequence> createFromResource(Context context, int textArrayResId, int textViewResId) { CharSequence[] strings = context.getResources().getTextArray(textArrayResId); return new ArrayAdapter<CharSequence>(context, textViewResId, strings); } }
/** * @param entryValuesResId The entry values array as a resource. * @see #setEntryValues(CharSequence[]) */ public void setEntryValues(int entryValuesResId) { setEntryValues(getContext().getResources().getTextArray(entryValuesResId)); }
/** * @param entriesResId The entries array as a resource. * @see #setEntries(CharSequence[]) */ public void setEntries(int entriesResId) { setEntries(getContext().getResources().getTextArray(entriesResId)); }
@Override public final void setMultiChoiceItems(@ArrayRes final int resourceId, @Nullable final boolean[] checkedItems, @Nullable final DialogInterface.OnMultiChoiceClickListener listener) { setMultiChoiceItems(getContext().getResources().getTextArray(resourceId), checkedItems, listener); }
public static void setEntries(@NonNull final Spinner spinner, @ArrayRes final int entriesResId) { final Context context = spinner.getContext(); final CharSequence[] entries = context.getResources().getTextArray(entriesResId); final CheckedTypedItemAdapter<CharSequence> adapter = new CheckedTypedItemAdapter<>(context, android.R.layout.simple_spinner_item, android.R.id.text1, entries); adapter.setDropDownViewResource(R.layout.asp_simple_spinner_dropdown_item); spinner.setAdapter(adapter); }
/** * @param entriesResId The entries array as a resource. * @see #setEntries(CharSequence[]) */ public void setEntries(@ArrayRes int entriesResId) { this.setEntries(this.getContext().getResources().getTextArray(entriesResId)); }
/** * @param entryValuesResId The entry values array as a resource. * @see #setEntryValues(CharSequence[]) */ public void setEntryValues(@ArrayRes int entryValuesResId) { this.setEntryValues(this.getContext().getResources().getTextArray(entryValuesResId)); }
/** * Sets the entries of the list, which is shown by the preference. * * @param resourceId * The resource id of the entries, which should be set, as an {@link Integer} value. The * resource id must correspond to a valid array resource */ public final void setEntries(@ArrayRes final int resourceId) { setEntries(getContext().getResources().getTextArray(resourceId)); }
@SmallTest public void testTextArray() { assertNotNull(testView.testTextArray); assertTrue(Arrays.deepEquals(testView.testTextArray, res.getTextArray(R.array.buzzwords))); assertNotNull(defaultsTestView.testTextArray); assertTrue(Arrays.deepEquals(defaultsTestView.testTextArray, res.getTextArray(R.array.buzzwords))); }