public HomePagerAdapter(FragmentManager fm, Context context) { super(fm); TITLES = context.getResources().getStringArray(R.array.sections); fragments = new Fragment[TITLES.length]; }
StringResourceSetting(String defaultValue, int resId) { super(defaultValue); Map<String, String> mapping = new HashMap<>(); String[] values = context.getResources().getStringArray(resId); for (String value : values) { mapping.put(value, value); } this.mapping = Collections.unmodifiableMap(mapping); }
IntegerResourceSetting(int defaultValue, int resId) { super(defaultValue); Map<Integer, String> mapping = new HashMap<>(); String[] values = context.getResources().getStringArray(resId); for (String value : values) { int intValue = Integer.parseInt(value); mapping.put(intValue, value); } this.mapping = Collections.unmodifiableMap(mapping); }
public StoreHouseHeader initWithStringArray(int id) { final View thisView = this; String[] points = thisView.getResources().getStringArray(id); List<float[]> pointList = new ArrayList<>(); for (String point : points) { String[] x = point.split(","); float[] f = new float[4]; for (int j = 0; j < 4; j++) { f[j] = Float.parseFloat(x[j]); } pointList.add(f); } initWithPointList(pointList); return this; }
/** * 得到字符数组 */ public static String[] getStringArray(Context context, int id) { return getResources(context).getStringArray(id); }
public UserProfileAdapter(Context context) { this.context = context; this.cellSize = Utils.getScreenWidth(context) / 3; this.photos = Arrays.asList(context.getResources().getStringArray(R.array.user_photos)); }
private void setupSpinnerAdapter() { ArrayAdapter<String> adapter = new ArrayAdapter<>( this, R.layout.item_spinner, getResources().getStringArray(R.array.interpolators)); adapter.setDropDownViewResource(R.layout.item_spinner_dropdown); mInterpolatorSpinner.setAdapter(adapter); }
Resources res = getResources(); TypedArray ta = res.obtainTypedArray(R.array.array0); int n = ta.length(); String[][] array = new String[n][]; for (int i = 0; i < n; ++i) { int id = ta.getResourceId(i, 0); if (id > 0) { array[i] = res.getStringArray(id); } else { // something wrong with the XML } } ta.recycle(); // Important!
public EatListElement(int requestCode) { super(getActivity().getResources().getDrawable(R.drawable.add_food), getActivity().getResources().getString(R.string.action_eating), null, requestCode); foodChoices = getActivity().getResources().getStringArray(R.array.food_types); foodUrls = getActivity().getResources().getStringArray(R.array.food_og_urls); }
@Override public void onClick(DialogInterface dialog, int which) { mTvFlipStyle.setText(getResources().getStringArray(R.array.setting_dialog_style_choice)[which]); SharedPreferencesUtil.getInstance().putInt(Constant.FLIP_STYLE, which); dialog.dismiss(); } })
SampleAdapter(FragmentManager mgr) { super(mgr); layouts=getLayoutsArray(R.array.layouts); titles=getResources().getStringArray(R.array.titles); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); type=findViewById(R.id.type); ArrayAdapter<String> types= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.types)); types.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); type.setAdapter(types); delay=findViewById(R.id.delay); }
@Nullable public String[] resolveStringArrayRes(@ArrayRes int resId) { if (resId != 0) { String[] cached = mResourceCache.get(resId); if (cached != null) { return cached; } String[] result = mResources.getStringArray(resId); mResourceCache.put(resId, result); return result; } return null; }
/** * Creates an adapter and sets it to an {@link AutoCompleteTextView} to enable suggestions. */ private void setUpAutoCompleteTextView() { String[] completions = getResources().getStringArray(R.array.bodies_of_water); ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, android.R.layout.simple_dropdown_item_1line, completions); AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.auto_complete_text_view); autoComplete.setAdapter(adapter); } }
private void requestDataList() { List<News> dataList = new ArrayList<>(); String[] titleArray = getResources().getStringArray(R.array.function_item_title); String[] contentArray = getResources().getStringArray(R.array.function_item_content); for (int i = 0; i < titleArray.length; i++) { News item = new News(); item.setTitle(titleArray[i]); item.setContent(contentArray[i]); dataList.add(item); } mView.setDataList(dataList); }
@Override public void onClick(DialogInterface dialog, int which) { mTvSort.setText(getResources().getStringArray(R.array.setting_dialog_sort_choice)[which]); SharedPreferencesUtil.getInstance().putBoolean(Constant.ISBYUPDATESORT, which == 0); EventManager.refreshCollectionList(); dialog.dismiss(); } })
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_private_process); privateProcessNameTextView = findViewById(R.id.textPrivateProcessName); setCurrentRunningProcess(privateProcessNameTextView, this); selectedListItemTextView = findViewById(R.id.selectedListItemText); ListView listView = findViewById(R.id.list); String[] listItems = getResources().getStringArray(R.array.list_items); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, listItems); listView.setAdapter(adapter); listView.setOnItemClickListener(this); }
@Override public void setSummary(@ArrayRes int summaryResId) { try { setSummary(getContext().getResources().getStringArray(summaryResId)); } catch (Exception e) { super.setSummary(summaryResId); } }
@Test public void getStringArray() throws Exception { assertThat(resources.getStringArray(R.array.items)).isEqualTo(new String[]{"foo", "bar"}); assertThat(resources.getStringArray(R.array.greetings)).isEqualTo(new String[]{"hola", "Hello"}); }
@Test public void asStringArray() { StringArrayTarget target = new StringArrayTarget(); String[] expected = context.getResources().getStringArray(R.array.string_one_two_three); Unbinder unbinder = new BindArrayTest$StringArrayTarget_ViewBinding(target, context); assertThat(target.actual).isEqualTo(expected); unbinder.unbind(); assertThat(target.actual).isEqualTo(expected); }