几天以来一直存在这个问题,我作为片段 A,在 onClick 事件中,另一个来自单独类的LaunchpadSectionFragment
Fragment( ) 被称为命名,正在调用并显示扩展。B
VideoPlayerFragment
ListFragment
问题:
当我单击片段 A 时,它会打开片段 B,片段 B 内部包含一个 listView - 由LoadAllProducts
数据库填充,然后onCreateView()
调用自定义数组适配器,该适配器将返回的记录加载到 listView 中。现在有时 Fragment B 会显示一个空白屏幕,然后如果我返回到上一个 Fragment(A) 然后返回到 B,它会显示 ListView。如果幸运的话,第一次加载 Frag B 时,它会显示 listView。我一直在为此苦苦挣扎。感谢您考虑。
public class CollectionDemoActivity extends FragmentActivity {
public static class DemoObjectFragment extends Fragment {
public static class LaunchpadSectionFragment extends ListFragment {
//onClick event opens another class which
//Extends another Fragment List
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.replace(R.id.contentFragment, fragment1, fragMainGroups );
transaction.addToBackStack(fragMainGroups);
transaction.commit();
}
}
}
VideoPlayerFragment.java
public class VideoPlayerFragment extends ListFragment {
public void onCreate(Bundle e){
super.onCreate(e);
productsList = new ArrayList<HashMap<String, ?>>();
db = new DatabaseHandler(getActivity().getBaseContext());
mContext = getActivity();
Log.d("Inside", "onCreate");
//this task will populate to get Data from database
//I checked in logcat and there are rows returned.
LoadAllProducts task = new LoadAllProducts();
task.execute();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//This custom array adapter is not sometimes called, sometimes not
//It really happens, I not sure with the reason. I also put some displays
//logs and sometimes it will execute the code, sometimes does not.
MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(
mContext, productsList,R.layout.load_groups_activity_listview, FolderNameGroups, selectedId);
setListAdapter(adapter);
}
}