开发者

how to get custom xml values in android?

I want to get the number of launcher:cellWidth in xml:

<mobi.intuitit.android.p.launcher.CellLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res/mobi.intuitit.android.p.launcher"

    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    launcher:cellWidth="80dip"
/>

I know that I ca开发者_开发知识库n get it in a Custom view by:

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);

        mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 100);

But how Can I get it in a Activity? not a Custom view. Thanks!


Your custom view should have a getter CellLayout.getCellWidth() and from your Activity, after finding you can get its value.

CellLayout cellLayout = (CellLayout)findViewById(R.id.cell_layout);

cellLayout.getCellWidth();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜