まあ私はAndroid Fragmentsを理解し始めていますが、これはまだ私にとっては混乱しています。私は少し助けが必要です。アンドロイドの断片はAPIレベル11以降でサポートされていますが、より低いレベルのAPI用には "support.v4"ライブラリパックをダウンロードできます。まず最初に、APIレベル15でフラグメントを試すための新しいプロジェクトを作成します。それから、APIレベル8で同じことをしましたが、うまくいきません...外付けのjarファイルをインポートしました。ここで問題になりますか?ここで下位APIのAndroidフラグメント
は私のメインクラスです:
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class Fragment2Activity extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
私の主なレイアウトXML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<fragment
android:name="com.frag.Fragment2.frag"
android:id="@+id/frag"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
マイフラグメントクラス:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class frag extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.hello_fragment, container, false);
return v;
}
}
そして、私のフラグメントレイアウトXML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text="THIS IS FRAGMENT"
android:background="@drawable/ic_launcher"
/>
</LinearLayout>
FIXED
これは役に立ちましたか?私は同じ問題を抱えています、あなたの修正は何ですか? – MikeIsrael