1package com.android.layoutlib.test.myapplication;
2
3import android.content.Context;
4import android.content.res.Resources;
5import android.util.AttributeSet;
6import android.widget.LinearLayout;
7import android.widget.TextView;
8
9/**
10 * A widget to test obtaining arrays from resources.
11 */
12public class ArraysCheckWidget extends LinearLayout {
13    public ArraysCheckWidget(Context context, AttributeSet attrs) {
14        this(context, attrs, 0);
15    }
16
17    public ArraysCheckWidget(Context context, AttributeSet attrs, int defStyleAttr) {
18        this(context, attrs, defStyleAttr, 0);
19    }
20
21    public ArraysCheckWidget(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
22        super(context, attrs, defStyleAttr, defStyleRes);
23        Resources resources = context.getResources();
24        for (CharSequence chars : resources.getTextArray(R.array.array)) {
25            addTextView(context, chars);
26        }
27        for (int i : resources.getIntArray(R.array.int_array)) {
28            addTextView(context, String.valueOf(i));
29        }
30        for (String string : resources.getStringArray(R.array.string_array)) {
31            addTextView(context, string);
32        }
33    }
34
35    private void addTextView(Context context, CharSequence string) {
36        TextView textView = new TextView(context);
37        textView.setText(string);
38        textView.setTextSize(30);
39        addView(textView);
40    }
41}
42