public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LayoutInflater inflater = getLayoutInflater();
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.main, (ViewGroup) findViewById(R.id.root));
Toast toast = new Toast(getApplicationContext());
toast.setView(layout);
toast.setDuration(2000);
toast.show();
}
This code throws an java.lang.IllegalArgumentException: View not attached to window manager. If i change the line
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.main, (ViewGroup) findViewById(R.id.root));
to
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.main, null);
works just fine.
Can someone explain me why this happening? I'm new to Android platform and i'm just trying to understand how views and windows manager works. Don't understand why if the root view was attached to Activity cannot be used anymore to a toast view.
Any help is appreciated!
Thanks!