私は Android Fragments を理解し始めていますが、これはまだ混乱しています。少し助けが必要です。AndroidフラグメントはAPIレベル11からサポートされていると言われていますが、下位レベルのAPI用の「support.v4」ライブラリパックをダウンロードできます。まず、APIレベル15でフラグメントを試すために新しいプロジェクトを作成します。次に、APIレベル8で同じことをしましたが、機能しません...外部jarをインポートしましたが、必要なインポートがすべて表示されます...ここで問題になりますか?
これが私のメインクラスです:
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>
修繕