Example usage for android.content.res TypedArray getTextArray

List of usage examples for android.content.res TypedArray getTextArray

Introduction

In this page you can find the example usage for android.content.res TypedArray getTextArray.

Prototype

public CharSequence[] getTextArray(@StyleableRes int index) 

Source Link

Document

Retrieve the CharSequence[] for the attribute at index.

Usage

From source file:com.liu.hz.view.ListView.java

public ListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, defStyle, 0);

    CharSequence[] entries = a.getTextArray(R.styleable.ListView_android_entries);
    if (entries != null) {
        setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries));
    }/*from   w  ww .ja  va2 s  .co  m*/

    final Drawable d = a.getDrawable(R.styleable.ListView_divider);
    if (d != null) {
        // If a divider is specified use its intrinsic width for divider width
        setDivider(d);
    }

    final Drawable osHeader = a.getDrawable(R.styleable.ListView_overScrollHeader);
    if (osHeader != null) {
        setOverscrollHeader(osHeader);
    }

    final Drawable osFooter = a.getDrawable(R.styleable.ListView_overScrollFooter);
    if (osFooter != null) {
        setOverscrollFooter(osFooter);
    }

    // Use the width specified, zero being the default
    final int dividerHeight = a.getDimensionPixelSize(R.styleable.ListView_dividerHeight, 0);
    if (dividerHeight != 0) {
        setDividerHeight(dividerHeight);
    }

    mHeaderDividersEnabled = a.getBoolean(R.styleable.ListView_headerDividersEnabled, true);
    mFooterDividersEnabled = a.getBoolean(R.styleable.ListView_footerDividersEnabled, true);

    a.recycle();
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

public HListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (LOG_ENABLED) {
        Log.i(LOG_TAG, "defStyle: " + defStyle);
    }//from   w w  w .jav a  2s  . co  m

    final Resources.Theme theme = context.getTheme();
    TypedArray array = theme.obtainStyledAttributes(attrs, R.styleable.HListView, defStyle, 0);

    CharSequence[] entries = null;
    Drawable dividerDrawable = null;
    Drawable overscrollHeader = null;
    Drawable overscrollFooter = null;
    int dividerWidth = 0;

    boolean headerDividersEnabled = true;
    boolean footerDividersEnabled = true;
    int measureWithChild = -1;

    if (null != array) {
        entries = array.getTextArray(R.styleable.HListView_android_entries);
        dividerDrawable = array.getDrawable(R.styleable.HListView_android_divider);
        overscrollHeader = array.getDrawable(R.styleable.HListView_hlv_overScrollHeader);
        overscrollFooter = array.getDrawable(R.styleable.HListView_hlv_overScrollFooter);
        dividerWidth = array.getDimensionPixelSize(R.styleable.HListView_hlv_dividerWidth, 0);
        headerDividersEnabled = array.getBoolean(R.styleable.HListView_hlv_headerDividersEnabled, true);
        footerDividersEnabled = array.getBoolean(R.styleable.HListView_hlv_footerDividersEnabled, true);
        measureWithChild = array.getInteger(R.styleable.HListView_hlv_measureWithChild, -1);
        array.recycle();

        if (LOG_ENABLED) {
            Log.d(LOG_TAG, "divider: " + dividerDrawable);
            Log.d(LOG_TAG, "overscrollHeader: " + overscrollHeader);
            Log.d(LOG_TAG, "overscrollFooter: " + overscrollFooter);
            Log.d(LOG_TAG, "dividerWith: " + dividerWidth);
            Log.d(LOG_TAG, "headerDividersEnabled: " + headerDividersEnabled);
            Log.d(LOG_TAG, "footerDividersEnabled: " + footerDividersEnabled);
            Log.d(LOG_TAG, "measureWithChild: " + measureWithChild);
        }
    }

    if (entries != null) {
        setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries));
    }

    if (dividerDrawable != null) {
        // If a divider is specified use its intrinsic height for divider height
        setDivider(dividerDrawable);
    }

    if (overscrollHeader != null) {
        setOverscrollHeader(overscrollHeader);
    }

    if (overscrollFooter != null) {
        setOverscrollFooter(overscrollFooter);
    }

    // Use the height specified, zero being the default
    if (dividerWidth != 0) {
        setDividerWidth(dividerWidth);
    }

    mHeaderDividersEnabled = headerDividersEnabled;
    mFooterDividersEnabled = footerDividersEnabled;
    mMeasureWithChild = measureWithChild;

}