TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CustomView); String text = array.getString(R.styleable.CustomView_text);
TypedArray array = getResources().obtainTypedArray(R.array.my_string_array); String text = array.getString(0);In this example, we are obtaining a TypedArray object from a resource array of strings. We then retrieve the first string value using the getString() method, passing in the index as a parameter. Both of these examples utilize the TypedArray class within the android.content.res package library.