0

チュートリアルから直接レイアウト XML ファイルがあります。

layout/partnertrial_summary.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

私のActivityクラスでは、次のコードを使用しようとしましたが、失敗した場合:

mTabHost = findViewById(R.layout.partnertrial_summary.tabhost);

これは失敗します。ただし、緑の部分を検証しますR.layout.partnertrial_summaryが、そのメンバーを自動ポップアップしようとするpartnertrial_summaryと何も得られません。

XMLはAndroidから直接来たので有効だと思います。それは私が間違っていることです。myActivityは ではありませんがTabActivity、通常のものを使用して を追加しTabHost、適切なリスナーを実装しても問題ないと思いました。私の考えが間違っていたら訂正してください。

4

1 に答える 1

1
mTabHost = findViewById(R.layout.partnertrial_summary.tabhost);

上記を以下のように置き換えます

LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.partnertrial_summary,null);
 mTabHost = (TabHost)view.findViewById(R.id.tabhost);

レイアウトは膨らませることができますが、findViewById() を使用して見つけることはできません

于 2012-04-23T17:59:35.773 に答える