Przy odtwarzaniu załadowany obraz się pokrywa zamiast dokonać zamiany. Czy idzie to rozwiązać w jakiś inny sposób bo już mi nerwy siadają >🙁 Chodzi mi o to aby utworzyć menu składające się z 4 rożnych aktywności. gdzie są one konstruowane dynamicznie z rożnych plików z folderu layout.
Z góry dziękuję.
importowana bibliotekę android-support-v4.jar aby program uruchamiał się w android 2.1
FragmentExampleActivity.java
package com.my;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
public class FragmentExampleActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
stackAFragment(3);
stackAFragment(1);
stackAFragment(3);
}
private void stackAFragment(int nAndroids) {
Fragment f3 = new Fragment3(nAndroids);
FragmentTransaction ft3 = getSupportFragmentManager().beginTransaction();
ft3.replace(R.id.the_frag3, f3);
ft3.commit();
}
}
Fragment3.java
package com.my;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment3 extends Fragment {
private int nAndroidsL;
public Fragment3() {
}
public Fragment3(int nAndroids) {
this.nAndroidsL = nAndroids;
}
public void onCreate(Bundle saved) {
super.onCreate(saved);
if (null != saved) {
nAndroidsL = saved.getInt("nAndroidsL");
}
}
public void onSaveInstanceState(Bundle toSave) {
toSave.putInt("nAndroidsL", nAndroidsL);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved) {
if(nAndroidsL == 0)
return inflater.inflate(R.layout.my_layout, container, false);
else
return inflater.inflate(R.layout.my_layout2, container, false);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment class="com.my.Fragment3"
android:id="@+id/the_frag3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
my_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="aaaa"/>
</LinearLayout>
my_layout2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="xxxx"/>
</LinearLayout>