Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting android:id for Linear layout component

I am using the drag and drop feature to add a Linear layout in my activity. when i check the activity_main.xml there is the component created but no "android:id" I cannot manually add the id , because there is no id for this layout in R.java . how to solve it?

like image 348
Vishnudev K Avatar asked Jun 22 '13 11:06

Vishnudev K


People also ask

What is the default value of orientation attribute in linear layout?

The default orientation is horizontal. orientation Pass HORIZONTAL or VERTICAL. Default value is HORIZONTAL.

What is Android ID attribute?

attributes: android:id. Resource ID. A unique resource name for the element, which you can use to obtain a reference to the View from your application.

What is layout_weight and weightSum in Android?

android:weightSum. Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.

What is RelativeLayout and LinearLayout in Android?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.


2 Answers

If you add android:id="@+id/YOUR_ID" to your XML, your IDE (I'm assuming eclipse) will recompile R.java, and you should be able to use R.id.YOUR_ID in your activity.

like image 160
Flynn81 Avatar answered Nov 15 '22 12:11

Flynn81


You needn't use R.id for setting id programmatically. You can use any positive number for id:

myNewLayout.setId(newLayoutIndex);

According to View documentation

The identifier does not have to be unique in this view's hierarchy. The identifier should be a positive number.

like image 27
Dimmerg Avatar answered Nov 15 '22 12:11

Dimmerg