Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inflate another view from another view in Android

I know in my onCreate() I can inflate a view from XML by something like:

loadingScreen = (RelativeLayout) findViewById(R.id.loadingScreen);

But how could I do this from another view? Im trying to call up a loading screen by setting its visibility from GONE to VISIBLE but cant seem to figure out how to do this from my glSurfaceView

like image 589
jfisk Avatar asked Nov 18 '25 09:11

jfisk


1 Answers

If you want to inflate a layout the code looks like this:

LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout myRoot = new LinearLayout(context);
View itemView = inflater.inflate(R.layout.layout_details, myRoot);

Here you first create a new LinearLayout an then inflate the layout with id R.layout.layout_details into it. The inflate method then returns the myRoot view.

Here is a tutorial about the LayoutInflater:

  • Layout resources in Android
like image 182
Dominik Mohr Avatar answered Nov 19 '25 23:11

Dominik Mohr