I am new in android.I have a simple doubt,Is there any way to get id of a widget from some layout without set it as content view ?? I am looking to invisible a view from a class .I used the code
View b = findViewById(R.id.id2);
b.setVisibility(View.GONE);
But error in "id",is it possible to get ids if widget from a java class without set as contentview ?? please help me. Thanks in advance :)
You can inflate the views separately and then use
findViewById
on the root of the inflated layout.At this point however these views are not part of your Activity's view hierarchy and will not be seen by the user. You will have to add them either by using
setContentView(root)
or by finding aViewGroup
in the current view hierarchy and callingviewGroup.addView(root)
.