I have this in my base Activity:
protected View createContentView( int id ) {
View view = inflate( id );
return createContentView( view );
}
public View createContentView( View view ) {
FrameLayout root = new FrameLayout( this );
root.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT ) );
LinearLayout pframe = new LinearLayout( this );
pframe.setId( R.id.INTERNAL_PROGRESS_CONTAINER_ID );
pframe.setOrientation( LinearLayout.VERTICAL );
pframe.setGravity( Gravity.CENTER );
ProgressBar progress = new ProgressBar( this, null,
android.R.attr.progressBarStyleLarge );
pframe.addView( progress, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT ) );
root.addView( pframe, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT ) );
FrameLayout lframe = new FrameLayout( this );
lframe.setId( R.id.INTERNAL_FRAGMENT_CONTAINER_ID );
lframe.setVisibility( View.GONE );
lframe.addView( view, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT ) );
root.addView( lframe, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT ) );
return root;
}
public void setContentShown( View view, boolean shown ) {
View progress = view.findViewById( R.id.INTERNAL_PROGRESS_CONTAINER_ID
);
View content = view.findViewById( R.id.INTERNAL_FRAGMENT_CONTAINER_ID );
if ( shown ) {
progress.startAnimation( AnimationUtils.loadAnimation( this,
R.anim.fade_out ) );
content.startAnimation( AnimationUtils.loadAnimation( this,
R.anim.fade_in ) );
progress.setVisibility( View.GONE );
content.setVisibility( View.VISIBLE );
} else {
progress.startAnimation( AnimationUtils.loadAnimation( this,
R.anim.fade_in ) );
content.startAnimation( AnimationUtils.loadAnimation( this,
R.anim.fade_out ) );
progress.setVisibility( View.VISIBLE );
content.setVisibility( View.GONE );
}
}
protected void setContentShown( boolean shown ) {
View root = findViewById( android.R.id.content );
setContentShown( root, shown );
}
Then in my Fragment I do the following:
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ) {
View view = inflater.inflate( R.layout.detail_view, container, false );
return createContentView( view );
}
Here detail_view is the actual content layout.
When my data is ready, I populate it in detail_view and then call:
setContentShown( true );
Hope this helps. BTW, this is fully inspired by ListFragment implementation
of content.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en