Hi I am trying to show a layout when a button is pressed but the layout is never shown. No exception is thrown for some reason. The button is located inside an activity. The button is called and declared and it works. The calling of the layout is just additional action to the button.
Here is my code to inflate the layout:
LayoutInflater layoutInflater = (LayoutInflater)getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View error = layoutInflater.inflate(R.layout.error_search_no_results,null);
Use this :
rv.addView(error);
Where rv is your parent layout.
Related
[When click on the button which is marked as circular line of image 1 then next functionality will be happen which is second image 2
is what you want to happen is that when you click the image button that row layer will hide?
You can add a layout at runtime using below snippet onClick of button.
LayoutInflater layoutInflater = getLayoutInflater();
View row = layoutInflater.inflate(R.layout.row, null);
ViewGroup main = (ViewGroup) findViewById(R.id.child_layout);
main.addView(row, 0);
R.layout.row is the row which you want to add on click of arrow.
R.id.child_layout will be an empty LinearLayout placeholder in your parent xml in which above row will be added.
You might want to look at various implementation of addView(), as it is overloaded with various parameters.
You can use removeView to remove the view as well.
There is one more option in which you can the add the row as part of layout set its visibility as GONE
e.g.
mainLayout.setVisibility(LinearLayout.GONE);
mainLayout.setVisibility(LinearLayout.VISIBLE);
And then you register or deregister click listeners.
I have a Linear layout and inside which there are few dropdown and text views,now i want to inflate the layout each time on click of "add more" button, below is the code for inflating the layout. the problem i am facing is to assign the id to each inflated layout content .Inorder to handle the content the inlfated layout i need the unique id for each content for each time i am inflating the layout.
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row_view;
row_view = (View)inflater.inflate(R.layout.inflatefloor,null);
inflatefloordetails.addView(row_view);
here inflatefloor is the layout to inflate and inflatefloordetails is the main root layout inside which layout is to be inflated and i am inflating the inflatefloor layout each time on button click.
New to android pardon if anyone finds the question silly.
Note:Check out link below if anyone is facing similar problem, I found this link useful.
How to set Id of dynamic created layout?
I think it will be helpful.
you can put any object when set the tag to be unique:
yourView.setTag(Object object);
and to retrive it:
object.indexOf(yourView.getTag())
Otherwise you have to use custom view.
i am inflating the layout using the layout inflator which had 10 editext field, when i click on the edittext soft keyboard hides the edittext if me does not inflate the layout and place in the setcontentview it workis fine. if a put requestfocus tag with inflating the layout crash the app. please find the below code and help me to resolve this.
JAVA CODE
LayoutInflater inflater = LayoutInflater.from(this);
scrollView = (MyHorizontalScrollView)
inflater.inflate(R.layout.horz_scroll_with_list_menu, null);
setContentView(scrollView);// if i comment this and add inflatelayout SetContentView(R.layout_details) works fine.
menu = inflater.inflate(R.layout.horz_scroll_menu, null);
app = inflater.inflate(R.layout.details, null);//
You may need to change an attribute in your manifest (for your Activity) to handle this. Put this line in your AndroidManifest.xml (within the tag you use to define your Activity)
android:windowSoftInputMode="adjustResize"
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
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
Thats actually not inflating. Inflating is the process that parses a XML layout file and creates a structure of View and ViewGroup class instances out of it (setContentView() does this for you in the background for example).
What you do is getting a reference to a view in code that you have defined in your XML layout file. To change the visibility of your GLSurfaceView you have to reference it like you did above. But remember that the View (GLSurfaceView in this case) has to be defined in your layout file.
After referencing you have to call GLSurfaceView.setVisibility() to change it's visibility.
Here's an example:
GLSurfaceView glsurface = (GLSurfaceView) findViewById(R.id.myglsurfaceid);
glsurface.setVisibility(View.VISIBLE);
Of course you can use View.INVISIBLE or View.GONE either, depending on what you want to do.
If you reference a layout (such as a RelativeLayout), you may find children of this layout with the findViewById() of your RelativeLayout instance:
RelativeLayour rl = (RelativeLayout) findViewById(R.id.mylayout);
(Button) mybutton = (Button) rl.findViewById(R.id.mybutton);
But thats usually not neccessary (at least when you just started with Android) because the activities findViewById() finds all Views that are displayed, even in sublayouts. You only have to use it if you have duplicate ids in your ui structure (tbh I never had that case yet) and want to specifiy where to look for your particular View.
You can't get a reference to a View that's doesn't exists in your current Layout, or your current View, (your current Activity content) , but you can create a new View from another XML layout, using LayoutInflater from current Activity.
you can add to you current Activity content, a new View, that's what you mentioned as " loading screen ", even by showing it as a Dialog or by creating View and then add it to root layout in your Activity
I hope I helped you
If I correctly understood what you wanna do:
Supposing you have a glSurfaceView object and you wanna grab a view that's inside that one.
You'll do just the same thing you did for you normal view. Let's say a button:
Button button = (Button) glSurfaceView.findViewById(R.id.buttonid);
If you meant something different let me know in the comments.
EDIT: And then you can just set the button's visibility:
button.setVisibility(Button.GONE)
I would like to achieve this layout :
my main activity layout (main.xml);
(Please mouse right click the following image and view image)
I have made another ContentActivity (with content set to content_one.xml) which is supposed to be used as part (the right part) of the above layout:
I know I can inflate a layout by:
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main);
LayoutInflater inflater = (LayoutInflater)Home2.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView = (View) inflater.inflate(R.layout.content_one, null);
mainLayout.addView(inflatedView);
I am wondering, besides inflate the content_one layout into main layout, is it possible to inflate a activity class instead of inflating a layout in android? If possible, how to do it?
You cant inflate an Activity as such. Consider using Fragments.
http://developer.android.com/guide/topics/fundamentals/fragments.html