RelativeLayout を拡張する TabView という名前のクラスを作成したいと考えています。これは、RelativeLayout を含む xml から拡張されます。問題は、私が期待したように機能していないようだということです。コンストラクタで何か間違ったことをしましたか? layoutInflater.inflate が View オブジェクトを返すことは知っていますが、それを何と等しくする必要がありますか? どんなアドバイスも大歓迎です!
private class TabView extends RelativeLayout {
private int mIndex;
public TabView(Context context) {
super(context, null, R.attr.vpiTabPageIndicatorStyle);
LayoutInflater layoutInflater = LayoutInflater.from(context);
layoutInflater.inflate(R.layout.tabview_title_subtitle, null);
}
public int getIndex() {
return mIndex;
}
public void setTitle() {
TextView title = (TextView)findViewById(R.id.title);
title.setText("Followers");
}
public void setSubitle() {
TextView subtitle = (TextView)findViewById(R.id.subtitle);
subtitle.setText("435");
}
}
以下は tabview_title_subtitle.xml です
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/title"
android:text="Subtitle"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>