0

几天以来一直存在这个问题,我作为片段 A,在 onClick 事件中,另一个来自单独类的LaunchpadSectionFragmentFragment( ) 被称为命名,正在调用并显示扩展。BVideoPlayerFragmentListFragment

问题:

当我单击片段 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);

       }

}

4

1 回答 1

0

感谢@Luksprog,给了我提示。为了确保 Custom Array Adapter 将在内部被调用ListFragment,我必须将 my MySimpleArrayAdapterinsideonPostExecute()放在 myAsyncTask上以确保它将在之后执行doBackground()

于 2013-08-02T02:21:29.330 回答