public MyCustomView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MyCustomView, defStyle, 0); try { CharSequence[] entries = a.getTextArray(R.styleable.MyCustomView_android_entries); if (entries != null) { //do something with the array if you want } } finally { a.recycle(); } }
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { setNegativeButtonText(android.R.string.cancel); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes); mEntries = a.getTextArray(R.styleable.ListPreference_entries); mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues); a.recycle(); /* Retrieve the Preference summary attribute since it's private * in the Preference class. */ a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.summary}, defStyleAttr, defStyleRes); mSummary = a.getString(0); a.recycle(); }
private void init(Context context, AttributeSet attrs, int defStyleAttr) { TypedArray a = context.obtainStyledAttributes(attrs, android.support.v7.appcompat.R.styleable.Spinner, defStyleAttr, 0); final CharSequence[] entries = a.getTextArray(R.styleable.Spinner_android_entries); if (entries != null) { final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context, R.layout.item_cute_spinner_item, entries); adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); setAdapter(adapter); } a.recycle(); } }
private void setup(Context context, AttributeSet attrs) { setDialogLayoutResource(R.layout.slider_preference_dialog); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SliderPreference); try { setSummary(a.getTextArray(R.styleable.SliderPreference_android_summary)); } catch (Exception e) { // Do nothing } a.recycle(); }
public IconListPreference(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0); CharSequence[] drawables; try { drawables = ta.getTextArray(R.styleable.IconListPreference_iconsDrawables); } finally { ta.recycle(); } for (CharSequence drawable : drawables) { int resId = context.getResources().getIdentifier(drawable.toString(), "mipmap", context.getPackageName()); Drawable d = context.getResources().getDrawable(resId); drawableList.add(d); } setWidgetLayoutResource(R.layout.item_icon_listpreference_preview); }
@Test public void getTextArray_whenNoSuchAttribute_shouldReturnNull() throws Exception { TypedArray typedArray = context.obtainStyledAttributes( Robolectric.buildAttributeSet() .addAttribute(android.R.attr.keycode, "@array/greetings") .build(), new int[]{android.R.attr.absListViewStyle}); CharSequence[] textArray = typedArray.getTextArray(0); assertThat(textArray).isInstanceOf(CharSequence[].class); for (CharSequence text : textArray) { assertThat(text).isNull(); } }
@Test public void getTextArray_shouldReturnValues() throws Exception { TypedArray typedArray = context.obtainStyledAttributes( Robolectric.buildAttributeSet() .addAttribute(R.attr.responses, "@array/greetings") .build(), new int[]{R.attr.responses}); assertThat(typedArray.getTextArray(0)).asList().containsExactly("hola", "Hello"); }
assertThat(refsTypedArray.getTextArray(8)) .asList().containsAllOf("abcdefg", "3875", "2.0", "#ffff00ff", "#00ffff", "8px", "12dp", "6dip", "3mm", "4in", "36sp", "18pt");
CharSequence[] array = a.getTextArray(R.styleable.MaterialCalendarView_mcv_weekDayLabels); if (array != null) { setWeekDayFormatter(new ArrayWeekDayFormatter(array)); array = a.getTextArray(R.styleable.MaterialCalendarView_mcv_monthLabels); if (array != null) { setTitleFormatter(new MonthArrayTitleFormatter(array));
mDividerMarginR = a.getDimensionPixelSize(attr, DEFAULT_DIVIDER_MARGIN_HORIZONTAL); }else if(attr == R.styleable.NumberPickerView_npv_TextArray){ mDisplayedValues = convertCharSequenceArrayToStringArray(a.getTextArray(attr)); }else if(attr == R.styleable.NumberPickerView_npv_TextColorNormal){ mTextColorNormal = a.getColor(attr, DEFAULT_TEXT_COLOR_NORMAL); mItemPaddingHorizontal = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_ITEM_PADDING_DP_H)); }else if(attr == R.styleable.NumberPickerView_npv_AlternativeTextArrayWithMeasureHint){ mAlterTextArrayWithMeasureHint = a.getTextArray(attr); }else if(attr == R.styleable.NumberPickerView_npv_AlternativeTextArrayWithoutMeasureHint){ mAlterTextArrayWithoutMeasureHint = a.getTextArray(attr); }else if(attr == R.styleable.NumberPickerView_npv_RespondChangeOnDetached){ mRespondChangeOnDetach = a.getBoolean(attr, DEFAULT_RESPOND_CHANGE_ON_DETACH);
setLabels(a.getTextArray(R.styleable.StepperIndicator_stpi_labels));
//obtain the array that refrences others array TypedArray plantArray=getResources().obtainTypedArray(R.array.plants); //obtain the referenced arrays CharSequence[] ginkoArray=plantArray.getTextArray(0); //... CharSequence[] orlayaArray=plantArray.getTextArray(3);
TypedArray a = context.obtainStyledAttributes(attrs, new int[] { R.attr.entries, R.attr.entryValues }); mEntries = a.getTextArray(0); // because R.attr.entries has index 0 in the passed array mEntryValues = a.getTextArray(1);
private final void initPreference(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UListPreference, 0, 0); if (a == null) return; mEntrySummaries = a.getTextArray(R.styleable.UListPreference_entrySummaries); a.recycle(); }
private final void initPreference(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UListPreference, 0, 0); if (a == null) return; mEntrySummaries = a.getTextArray(R.styleable.UListPreference_entrySummaries); a.recycle(); }
private void initPreference(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IjkListPreference, 0, 0); if (a == null) return; mEntrySummaries = a .getTextArray(R.styleable.IjkListPreference_entrySummaries); a.recycle(); }
@Override protected final Object onGetDefaultValue(final TypedArray typedArray, final int index) { CharSequence[] defaultValues = typedArray.getTextArray(index); if (defaultValues != null) { Set<String> defaultValue = new HashSet<>(); for (CharSequence value : defaultValues) { defaultValue.add(value.toString()); } return defaultValue; } return null; }
private void init(final @NonNull Context context, @Nullable final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ColorPreference, defStyleAttr, defStyleRes); final int colorValuesRes = a.getResourceId(R.styleable.ColorPreference_android_entryValues, 0); if (colorValuesRes != 0) { mColorValues = arrayResToColors(context, colorValuesRes); } mColorNames = a.getTextArray(R.styleable.ColorPreference_android_entries); //noinspection WrongConstant mSwatchSize = a.getInteger(R.styleable.ColorPreference_asp_swatchSize, DEFAULT_SWATCH_SIZE); mColumnCount = a.getInteger(R.styleable.ColorPreference_asp_columnCount, DEFAULT_COLUMN_COUNT); a.recycle(); }
private void init(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes); mEntries = a.getTextArray(R.styleable.ListPreference_android_entries); mEntryValues = a.getTextArray(R.styleable.ListPreference_android_entryValues); a.recycle(); }
public EmergencyListPreference(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EmergencyListPreference); mContentDescriptions = a.getTextArray(R.styleable.EmergencyListPreference_entryContentDescriptions); a.recycle(); if (mContentDescriptions != null) { // Override entries with accessible entries. setEntries(createAccessibleEntries(getEntries(), mContentDescriptions)); } }