Back to project page fragmentHost.
The source code is released under:
MIT License
If you think the Android project fragmentHost listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.chechezhi.fh; /*from w w w .j a v a 2 s.c o m*/ import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v4.app.Fragment; import android.support.v4.app.LoaderManager; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.TextView; public class FirstFragment extends Fragment { private View mFinalView; private Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { FrameLayout rootFrameLayout = (FrameLayout) getView().findViewById(R.id.view_root); rootFrameLayout.findViewById(R.id.loading_splash).setVisibility(View.GONE); rootFrameLayout.addView(mFinalView); super.handleMessage(msg); } }; @Override public LoaderManager getLoaderManager() { // TODO Auto-generated method stub return super.getLoaderManager(); } @Override public boolean getUserVisibleHint() { // TODO Auto-generated method stub return super.getUserVisibleHint(); } @Override public View getView() { // TODO Auto-generated method stub return super.getView(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_loading, container, false); } @Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { // TODO Auto-generated method stub super.onInflate(activity, attrs, savedInstanceState); } @Override public void onLowMemory() { // TODO Auto-generated method stub super.onLowMemory(); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { if (mFinalView != null) { mHandler.sendEmptyMessage(0); } else { prepareFinalViewAsync(); } super.onViewCreated(view, savedInstanceState); } private void prepareFinalViewAsync() { Thread t = new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(3000); TextView tv = new TextView(getActivity()); tv.setText("I'm finished"); mFinalView = tv; mHandler.sendEmptyMessage(0); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); t.start(); } @Override public void setTargetFragment(Fragment fragment, int requestCode) { // TODO Auto-generated method stub super.setTargetFragment(fragment, requestCode); } }