Language

Fragment.OnInflate メソッド

定義

オーバーロード

Name 説明
OnInflate(IAttributeSet, Bundle)
古い.

このメソッドは、API レベル 15 では非推奨になりました。

OnInflate(Activity, IAttributeSet, Bundle)
古い.

このメソッドは、API レベル 23 では非推奨になりました。

OnInflate(Context, IAttributeSet, Bundle)

フラグメントがビュー レイアウトのインフレーションの一部として作成されるときに呼び出されます。通常は、アクティビティのコンテンツ ビューの設定から呼び出されます。

OnInflate(IAttributeSet, Bundle)

注意事項

deprecated

このメソッドは、API レベル 15 では非推奨になりました。

[Android.Runtime.Register("onInflate", "(Landroid/util/AttributeSet;Landroid/os/Bundle;)V", "GetOnInflate_Landroid_util_AttributeSet_Landroid_os_Bundle_Handler")]
[System.Obsolete("deprecated")]
public virtual void OnInflate(Android.Util.IAttributeSet? attrs, Android.OS.Bundle? savedInstanceState);
[<Android.Runtime.Register("onInflate", "(Landroid/util/AttributeSet;Landroid/os/Bundle;)V", "GetOnInflate_Landroid_util_AttributeSet_Landroid_os_Bundle_Handler")>]
[<System.Obsolete("deprecated")>]
abstract member OnInflate : Android.Util.IAttributeSet * Android.OS.Bundle -> unit
override this.OnInflate : Android.Util.IAttributeSet * Android.OS.Bundle -> unit

パラメーター

attrs
IAttributeSet

AttributeSet

savedInstanceState
Bundle

Bundle

属性

注釈

このメソッドは、API レベル 15 では非推奨になりました。 代わりに onInflate(Context,AttributeSet,Bundle) を使用してください。

このメソッドをオーバーライドする場合は、スーパークラス実装を呼び出す必要があります。

android.app.Fragment.onInflateの Android リファレンス。

このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。

適用対象

OnInflate(Activity, IAttributeSet, Bundle)

注意事項

deprecated

このメソッドは、API レベル 23 では非推奨になりました。

[Android.Runtime.Register("onInflate", "(Landroid/app/Activity;Landroid/util/AttributeSet;Landroid/os/Bundle;)V", "GetOnInflate_Landroid_app_Activity_Landroid_util_AttributeSet_Landroid_os_Bundle_Handler")]
[System.Obsolete("deprecated")]
public virtual void OnInflate(Android.App.Activity? activity, Android.Util.IAttributeSet? attrs, Android.OS.Bundle? savedInstanceState);
[<Android.Runtime.Register("onInflate", "(Landroid/app/Activity;Landroid/util/AttributeSet;Landroid/os/Bundle;)V", "GetOnInflate_Landroid_app_Activity_Landroid_util_AttributeSet_Landroid_os_Bundle_Handler")>]
[<System.Obsolete("deprecated")>]
abstract member OnInflate : Android.App.Activity * Android.Util.IAttributeSet * Android.OS.Bundle -> unit
override this.OnInflate : Android.App.Activity * Android.Util.IAttributeSet * Android.OS.Bundle -> unit

パラメーター

activity
Activity

Activity

attrs
IAttributeSet

AttributeSet

savedInstanceState
Bundle

Bundle

属性

注釈

このメソッドは、API レベル 23 では非推奨になりました。 代わりに onInflate(Context,AttributeSet,Bundle) を使用してください。

このメソッドをオーバーライドする場合は、スーパークラス実装を呼び出す必要があります。

android.app.Fragment.onInflateの Android リファレンス。

このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。

適用対象

OnInflate(Context, IAttributeSet, Bundle)

フラグメントがビュー レイアウトのインフレーションの一部として作成されるときに呼び出されます。通常は、アクティビティのコンテンツ ビューの設定から呼び出されます。

[Android.Runtime.Register("onInflate", "(Landroid/content/Context;Landroid/util/AttributeSet;Landroid/os/Bundle;)V", "GetOnInflate_Landroid_content_Context_Landroid_util_AttributeSet_Landroid_os_Bundle_Handler", ApiSince=23)]
public virtual void OnInflate(Android.Content.Context? context, Android.Util.IAttributeSet? attrs, Android.OS.Bundle? savedInstanceState);
[<Android.Runtime.Register("onInflate", "(Landroid/content/Context;Landroid/util/AttributeSet;Landroid/os/Bundle;)V", "GetOnInflate_Landroid_content_Context_Landroid_util_AttributeSet_Landroid_os_Bundle_Handler", ApiSince=23)>]
abstract member OnInflate : Android.Content.Context * Android.Util.IAttributeSet * Android.OS.Bundle -> unit
override this.OnInflate : Android.Content.Context * Android.Util.IAttributeSet * Android.OS.Bundle -> unit

パラメーター

context
Context

このフラグメントを膨らませるコンテキスト。

attrs
IAttributeSet

フラグメントが作成されているタグの属性。

savedInstanceState
Bundle

フラグメントが以前に保存された状態から再作成されている場合、これは状態です。

属性

注釈

フラグメントがビュー レイアウトのインフレーションの一部として作成されるときに呼び出されます。通常は、アクティビティのコンテンツ ビューの設定から呼び出されます。 これは、レイアウト ファイル内のタグからフラグメントが作成された直後に呼び出すことができます。 これはフラグメントの onAttach(Activity) が呼び出される前であることに注意してください。ここで行う必要があるのは、属性を解析して保存することです。 これは、保存された状態の新しいインスタンスに拡張されている場合でも、フラグメントが膨張するたびに呼び出されます。 通常は、パラメーターを毎回再解析して、異なる構成で変更できるようにすることが理にかなっています。

ここで提供される属性と getArguments() の両方を通じてパラメーターを受け取ることができるフラグメントの一般的な実装を次に示します。

public static class MyFragment extends Fragment {
    CharSequence mLabel;

    /**
     * Create a new instance of MyFragment that will be initialized
     * with the given arguments.
     */
    static MyFragment newInstance(CharSequence label) {
        MyFragment f = new MyFragment();
        Bundle b = new Bundle();
        b.putCharSequence("label", label);
        f.setArguments(b);
        return f;
    }

    /**
     * Parse attributes during inflation from a view hierarchy into the
     * arguments we handle.
     */
    @Override public void onInflate(Activity activity, AttributeSet attrs,
            Bundle savedInstanceState) {
        super.onInflate(activity, attrs, savedInstanceState);

        TypedArray a = activity.obtainStyledAttributes(attrs,
                R.styleable.FragmentArguments);
        mLabel = a.getText(R.styleable.FragmentArguments_android_label);
        a.recycle();
    }

    /**
     * During creation, if arguments have been supplied to the fragment
     * then parse those out.
     */
    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle args = getArguments();
        if (args != null) {
            mLabel = args.getCharSequence("label", mLabel);
        }
    }

    /**
     * Create the view for this fragment, using the arguments given to it.
     */
    @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.hello_world, container, false);
        View tv = v.findViewById(R.id.text);
        ((TextView)tv).setText(mLabel != null ? mLabel : "(no label)");
        tv.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.gallery_thumb));
        return v;
    }
}

XML 属性を解析すると、"スタイル可能な" リソースが使用されることに注意してください。 ここで使用する styleable の宣言は次のとおりです。

<declare-styleable name="FragmentArguments">
<attr name="android:label" />
</declare-styleable>

フラグメントは、次のようなタグを使用して、アクティビティのコンテンツ レイアウト内で宣言できます。

<fragment class="com.example.android.apis.app.FragmentArguments$MyFragment"
        android:id="@+id/embedded"
        android:layout_width="0px" android:layout_height="wrap_content"
        android:layout_weight="1"
        android:label="@string/fragment_arguments_embedded" />

このフラグメントは、実行時に引数 Bundle で指定された引数から動的に作成することもできます。包含アクティビティの作成時にこれを行う例を次に示します。

@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_arguments);

    if (savedInstanceState == null) {
        // First-time init; create fragment to embed in activity.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        Fragment newFragment = MyFragment.newInstance("From Arguments");
        ft.add(R.id.created, newFragment);
        ft.commit();
    }
}

android.app.Fragment.onInflateの Android リファレンス。

このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。

適用対象