私は断片についてのチュートリアルに従ってきましたが、それらに少し触れました。チュートリアルを最後までたどりましたが、Eclipse がエラーをスローしています。以前に発生していた問題と"The method Fragment1() is undefined for the type MainActivity"
関係があるかどうかはわかりません。Import.R.Android.*
そして今は言及していませんFragment1.class?
か、フラグメントを初期化するチュートリアルで何かが見落とされていますか?
public void Onclick(View v) {
Fragment newFragment;
if (v == button1) {
newFragment = Fragment1();
}else if (v == button2) {
newFragment = Fragment2();
}else if (v == button3) {
newFragment = Fragment3();
}else {
newFragment = StartFragment();
}
}
Fragment(newFragment)
どのボタンが押されたかに基づいて、プレースホルダーをフラグメントに置き換えますか? それとも、明らかなはずの何かが欠けていますか? 助けてくれてありがとう。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:baselineAligned="false" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Onclick"
android:text="Frag1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Onclick"
android:text="Frag2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="OnClick"
android:text="Frag3" />
</LinearLayout>
<LinearLayout
android:id="@+id/myFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
TLDR: フラグメントが定義されていないため、それはわかっていますが、チュートリアルに従っていたので、フラグメントを定義する方法がまだわかりません。
Android 開発者ガイドは、このチュートリアルとは異なる方法で実装しているように見えるため、この特定のケースでは役に立ちません。