I am probably just misusing the XML, but I'm trying to create a layout for a list view row, but I seem to be failing miserably.
I have this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<TextView android:id="#+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/detailsTextView"
android:textSize="16sp"/>
<TextView android:id="#id/detailsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"/>
</RelativeLayout>
In hopes that I will be able to add a layout that is 100dp in height to my ListView and have two TextViews inside of it. However, when I try to set it up like so:
public View getView(int position, View currentView, ViewGroup parent)
{
View rowContents = LayoutInflater.from(mContext).inflate(R.layout.list_view_cell, null);
TextView titleView = (TextView)rowContents.findViewById(R.id.titleTextView);
titleView.setText(titles[position]);
TextView detailsView = (TextView)rowContents.findViewById(R.id.detailsTextView);
detailsView.setText(details[position]);
return rowContents;
}
It's giving me a row with only my detailsView TextViewwith a wrap_content height, it seems. The titleView is nowhere to be seen and I would assume the rowContents isn't being set either, otherwise the height would be 100dp, right?
I know I should be reusing the old view and setting its contents, but I just made this up quickly as a test.
What is going wrong here?
Try setting the lower TextView with layout_below instead:
<TextView android:id="#+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"/>
<TextView android:id="#+id/detailsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/titleTextView"
android:textSize="12sp"/>
(Otherwise you could "lock" titleTextView into the upper lefthand corner, which might force detailsTextView to move down.)
But you should watch this Google Talk by one of Android's lead programmers, it gives great detail on how to make an efficient adapter.
Related
The main goal is to use a pre-made layout to create separate modules that can be edited, and then programmatically add them to the root layout. To clarify, several modules stuck together would look like this. I would like to dynamically create each clickable block that consists of a name, date, and letter. The .axml code for each block is as follows:
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/borderLayout"
android:background="#drawable/line"
android:paddingBottom="1dp"
android:paddingTop="1dp">
<RelativeLayout
android:id="#+id/relativeLayout1"
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:background="#ff2f2f2f">
<TextView
android:text="C"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:layout_alignParentLeft="true"
android:textSize="30dp" />
<TextView
android:text="Washington"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/textView1"
android:id="#+id/textView2"
android:layout_alignParentRight="true"
android:gravity="right" />
<TextView
android:text="6-8-17"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView2"
android:id="#+id/textView3"
android:gravity="right"
android:layout_alignParentRight="true" />
</RelativeLayout>
</RelativeLayout>
The main problem I am having is formatting the views programmatically in the same way that I formatted them in the .axml file.
Lets assume you have a LinearLayout with an orientation of vertical in your main axml that you wish to attach multiple views to.
Get a reference to that "parent" LinearLayout:
var linearLayoutParent = FindViewById<LinearLayout>(Resource.Id.linearLayout1);
Then in some loop, use LayoutInflater.Inflate to inflate your repeating layout, use the view returned and FindViewById on that View each of the elements you need to update and then add that view to the parent view with an increasing index:
index++;
var view = LayoutInflater.Inflate(Resource.Layout.RepeatingLayout, linearLayoutParent, false);
var letter = view.FindViewById<TextView>(Resource.Id.textView1);
letter.Text = index.ToString();
// FindViewById for textView2, textView3 and assign the text on each....
linearLayoutParent.AddView(view, index);
Note: If you have a lot of these repeating elements and you will have to scroll them (off screen), look at using a RecyclerView instead, it will save you a lot of headaches into terms of memory management, scrolling performance, etc... ;-)
Use inflater to create a view from resource. Then you can add it programmatically
context.LayoutInflater.Inflate(Resource.Layout.oneimg_twolbl, null);
I am struggling to debug a weird UI glitch for listviews in my android app. 99% of the time everything looks and works like it should, but every now and then my listviews behave strangely. When you restart the app the listview looks normal again.
Does anyone know if this is a known android bug?
The fact that it only happens at random (I have tried to figure out a pattern and cant) scares me. I havent been able to find anything online regarding similar issues. Hopefully I've just been googling the wrong search-terms.
Any advice/help would be much appreciated.
Thanks in advance.
What the Listview usually looks like:
What the listview looks like every now and then:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="#dimen/tile_height_padded"
android:descendantFocusability="blocksDescendants"
android:layout_margin="0dp"
android:padding="#dimen/padding_list">
<!--This is the clickable background of the item-->
<ImageView
android:id="#+id/imageview_poi_tile_detail_button_detail"
android:background="#color/ca"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_toLeftOf="#+id/imageview_poi_tile_map_button"/>
<!--This is the Grey vertical line next to the icon on the left-->
<ImageView
android:id="#+id/delimiter_poi_tile"
android:layout_width="#dimen/delimiter_size"
android:layout_height="#dimen/tile_description_height"
android:layout_marginTop="#dimen/margin_list_vertical"
android:layout_marginBottom="#dimen/margin_list_vertical"
android:background="#color/git"
android:layout_toRightOf="#id/imageview_poi_tile_icon"/>
<!--This is the red map button on the right-->
<ImageView
android:id="#id/imageview_poi_tile_map_button"
android:background="#color/lr"
android:src="#drawable/map"
android:scaleType="fitCenter"
android:padding="#dimen/image_button_padding"
android:layout_width="#dimen/button_size"
android:layout_height="match_parent"
android:layout_alignParentRight="true"/>
<!--This is the marker Icon on the left-->
<ImageView
android:id="#+id/imageview_poi_tile_icon"
android:src="#drawable/poidefaultgit"
android:scaleType="fitStart"
android:padding="#dimen/image_button_padding"
android:background="#color/ca"
android:layout_width="#dimen/button_size"
android:layout_height="#dimen/tile_description_height"
android:layout_margin="0dp"/>
<!--This is the bold title text, eg. BARONS-->
<TextView
android:id="#+id/textview_poi_tile_type"
android:background="#color/ca"
android:paddingLeft="#dimen/padding_list"
android:layout_margin="0dp"
android:gravity="left|top"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:text="Poi Type"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/git"
android:layout_width="match_parent"
android:layout_height="#dimen/tile_title_height"
android:layout_toRightOf="#id/delimiter_poi_tile"
android:layout_toLeftOf="#+id/textview_poi_tile_distance"/>
<!--This is the address that is shown, eg 3 ADDERLEY ST, CAPE TOWN,-->
<TextView
android:id="#+id/textview_poi_tile_description"
android:background="#color/ca"
android:paddingLeft="#dimen/padding_list"
android:layout_margin="0dp"
android:gravity="left|top"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Address"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/git"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/textview_poi_tile_type"
android:layout_toRightOf="#id/delimiter_poi_tile"
android:layout_toLeftOf="#id/imageview_poi_tile_map_button"/>
<!--This will display a string when the gps is on, not shown in image as gps was off in screenshot-->
<TextView
android:id="#id/textview_poi_tile_distance"
android:background="#color/ca"
android:textColor="#color/lr"
android:text=""
android:paddingRight="#dimen/padding_list"
android:layout_margin="0dp"
android:gravity="left|top"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/imageview_poi_tile_map_button"/>
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
TextView description;
TextView type;
TextView distance;
ImageView imageView;
ImageView mapIcon;
ImageView clickableArea;
if(convertView == null)
{
convertView = LayoutInflater.from(context).inflate(R.layout.listitem_poi, parent, false);
description = (TextView) convertView.findViewById(R.id.textview_poi_tile_description);
type = (TextView) convertView.findViewById(R.id.textview_poi_tile_type);
distance = (TextView) convertView.findViewById(R.id.textview_poi_tile_distance);
imageView = (ImageView) convertView.findViewById(R.id.imageview_poi_tile_icon);
mapIcon = (ImageView) convertView.findViewById(R.id.imageview_poi_tile_map_button);
clickableArea = (ImageView) convertView.findViewById(R.id.imageview_poi_tile_detail_button_detail);
convertView.setTag(new ViewHolder(description, type, distance, imageView, mapIcon, clickableArea));
}
else
{
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
description = viewHolder.description;
type = viewHolder.type;
distance = viewHolder.distance;
imageView = viewHolder.imageView;
mapIcon = viewHolder.mapIcon;
clickableArea = viewHolder.clickableArea;
}
final int finalIndex = position;
final PointOfInterest poi = getItem(position);
description.setText(poi.getDescription());
type.setText(poi.getName());
imageView.setImageResource(R.drawable.poidefaultgit);
distance.setText(poi.getDistance());
return convertView;
}
I think there are several things that are causing this. From experience, I've noticed RelativeLayout will sometimes not appropriately size it's children based on available space. It'll sooner let something get clipped if one of the sides of a child is not properly bounded somewhere. Also, I think some of the sizes for the TextViews just aren't enough to display the text. I did the following off the top of my head here so it may need some tweaking, however it should paint the picture of the layout to try. Unfortunately its not as flat as your current XML but it should hopefully fix your problem. Sorry not at a computer to test this currently.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--This is the marker Icon on the left-->
<!--Use margin if you need more space to divider-->
<ImageView
android:id="#+id/imageview_poi_tile_icon"
android:src="#drawable/poidefaultgit"
android:scaleType="fitStart"
android:padding="#dimen/image_button_padding"
android:background="#color/ca"
android:layout_width="#dimen/button_size"
android:layout_height="match_parent"/>
<!--This is the Grey vertical line next to the icon on the left-->
<!--Use margin to determine how close the line is to the top/bottom of item-->
<ImageView
android:id="#+id/delimiter_poi_tile"
android:layout_width="#dimen/delimiter_size"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/margin_list_vertical"
android:layout_marginBottom="#dimen/margin_list_vertical"
android:src="#color/git"
android:background="#color/ca"/>
<RelativeLayout
android:gravity="center_vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#color/ca">
<!--This is the bold title text, eg. BARONS-->
<TextView
android:id="#+id/textview_poi_tile_type"
android:paddingLeft="#dimen/padding_list"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:text="Poi Type"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/git"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!--This is the address that is shown, eg 3 ADDERLEY ST, CAPE TOWN,-->
<TextView
android:id="#+id/textview_poi_tile_description"
android:paddingLeft="#dimen/padding_list"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Address"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/git"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textview_poi_tile_type"/>
<!--This will display a string when the gps is on, not shown in image as gps was off in screenshot-->
<TextView
android:id="#id/textview_poi_tile_distance"
android:textColor="#color/lr"
android:text=""
android:paddingRight="#dimen/padding_list"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/textview_poi_tile_type"/>
</RelativeLayout>
<!--This is the red map button on the right-->
<ImageButton
android:id="#id/imageview_poi_tile_map_button"
android:background="#color/lr"
android:src="#drawable/map"
android:scaleType="fitCenter"
android:padding="#dimen/image_button_padding"
android:layout_width="#dimen/button_size"
android:layout_height="match_parent"/>
</LinearLayout>
The idea here is to have the entire item in a LinearLayout that wraps to the size of the contents. Rely on it for getting everything horizontally in place. Then only wrap the TextViews in a Relativelayout. Just have the TextViews align beneath and to the side of each other. Have the RelativeLayout worry about actually centering them accordingly. It's weighted to ensure it stretches to fill any remaining space horizontally.
Also, your map button can be an ImageButton. You don't need a view solely to take the item click event. The root layout itself can do it as is. You probably ran into an issue with this setup. Check out this post which tells you how to properly get a row to click when an ImageButton is embedded.
Try inflating a new view every time instead of re-using them. I know it isn't the best thing to do, but at some point i had similar problems and this was the only thing that worked.
Thanks for the help. I managed to clean up the layout file a lot.
The reason that the UI glitch was happening is due to the wrong style file being loaded. It only happened when I loaded another element before that used that style. To solve it I created a new style specifically for the listviews and assigned it to the listview elements.
Update: I am sorry i pasted in list.xml twice by mistake, my question is now correct!...
I created a class which extends ArrayAdapter, in which I override getView, and in there I capture controls in my row.xml, and setText on them appropiately with my values. This all works fine, I got no problem here.
What I then tried to do is have my output in tabular format, so I can span columns etc and get them all aligned as I wish. Here start my problem.
So I lave my two xml files, one for my list, and one for the row. In the list I define a TableLayout, with nothing in it except my ListView. Not how I set my stretchColumns property? Then in row.xml, I just define a TableRow, so I would expect to get a load of TableRows tags created inbetween the TableLayout start and end tags, and everything will turn out good.
Well it does work in the sense that I can see teh results, HOWEVER all of the TableRows are not aligned with the rest of thd table, or other rows. They just all get sixed to fit there own contents, and seems they are not properly a part of my TableLayout at all.
If I create by hand the xml I would EXPECT to be inflated in my custom adapter, and put it between the TableLayout tags (and remove the ListView) everything displays perfectly, columns aligned etc.
Perhaps I am doing something wrong, or perhaps I should not be using a TableLayout this way and ought to be doing things a different way.
Really appreciate any helps with this, been stuck puzzled on if for ages.
this is row.xml
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvQty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="QTY"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvPartName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingLeft="10dip"
android:text="Part desererregre"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvPartCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:paddingLeft="10dip"
android:text="PART CODE"
android:textSize="12dp"
android:textStyle="bold" />
</TableRow>
this is my list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/addCallPart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Button" />
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:stretchColumns="1" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</TableLayout>
<TextView
android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="There are no records." />
</LinearLayout>
here is my code, this all works ok, but i include it to make the question clearer
public class CallPartAdapter extends ArrayAdapter<CallPart> {
private final Context context;
private final List<CallPart> values;
public CallPartAdapter(Context context, List<CallPart> values) {
super(context, R.layout.row, values);
this.context = context;
this.values = values;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.row, parent, false);
TextView textView1 = (TextView) rowView.findViewById(R.id.tvQty);
TextView textView2 = (TextView) rowView.findViewById(R.id.tvPartName);
TextView textView3 = (TextView) rowView.findViewById(R.id.tvPartCode);
textView1.setText(Integer.toString(values.get(position).Qty));
textView2.setText(values.get(position).PartName);
textView3.setText(values.get(position).PartCode);
return rowView;
}
}
You can't use TableLayout that way. Well, let me rephrase... you can but you won't get the results you desire. You've essentially got a TableLayout with a single row: the ListView. So none of the items in your ListView will receive any of the layout benefit of being in a TableLayout. They are simply ListView items.
You have two real options:
Dynamically add your rows to the TableLayout. You can still use an adapter, but it won't buy you much, since you'll simply be using it as a List.
Modify your row layout to provide a TableLayout style of layout and stick with the ListView parent.
I am currently working on an Activity that features components with weight. Those components contain text and icons. As far as I know, android does not provide features to scale text according to it's parent view. As a consequence, I need to measure those views and then manually apply my custom font to the TextViews and set an appropriate font size.
I am currently doing it the following way (Which actually works. But I often get 09-30 17:55:14.844: ERROR/ViewRoot(12893): OutOfResourcesException locking surface
) errors and I believe this might be connected to the way I do my layout.
This is one row in the layout (there are several rows)
<RelativeLayout
android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_weight="0.35"
android:id="#+id/activity_main_row_1">
<View
android:layout_width="6dip"
android:layout_height="fill_parent"
android:background="#color/palette_green"
android:layout_alignParentLeft="true"
/>
<RelativeLayout
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingLeft="20dip">
<TextView
android:id="#+id/activity_main_row_1_title"
android:text="#string/title_add_expense"
android:textSize="10dip"
android:textColor="#color/palette_grey"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0px">
</TextView>
<TextView
android:id="#+id/activity_main_row_1_sub_title"
android:text="#string/subtitle_add_expense"
android:textSize="10dip"
android:textColor="#color/palette_dark_grey"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0px"
android:layout_below="#+id/activity_main_row_1_title">
</TextView>
</RelativeLayout>
<ImageView
android:id="#+id/activity_main_row_1_bracket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_bracket_right_grey"
android:paddingLeft="0dip"
android:paddingRight="0dip"
android:paddingTop="24dip"
android:paddingBottom="20dip"
android:layout_alignParentRight="true">
</ImageView>
</RelativeLayout>
This is the way I do the measurements:
in onCreate:
LinearLayout mLayout = (LinearLayout) this.getLayoutInflater().inflate(R.layout.activity_main, null);
mLayout.getViewTreeObserver().addOnGlobalLayoutListener(this);
this.setContentView(mLayout);
In onGlobalLayout:
#Override
public void onGlobalLayout() {
int mRow1Height = mRow1.getHeight();
<omitted>
if(mRow1Height>0) {
TextView row1Title = (TextView) findViewById(R.id.activity_main_row_1_title);
row1Title.setTypeface(mFontProvider.getTypeface());
row1Title.setTextSize((float) ((mRow1Height)*.3));
TextView row1SubTitle = (TextView) findViewById(R.id.activity_main_row_1_sub_title);
row1SubTitle.setTypeface(mFontProvider.getTypeface());
row1SubTitle.setTextSize((float) ((mRow1Height)*.2));
}
Is this the correct way to do what I want to do?
Thanks so much for your advice.
Cheers
I found the issue that was causing the OutOfResourcesExceptions. In the onLayout, I set the text for a TextView. This causes the view to be laid out again, resulting in kind of an an infinite loop.
I'd however still be interested in knowing if using addOnGlobalLayoutListener and onLayout is the only way to scale TextViews in respect to their dynamically sized parent views.
Edition of question
It is already in a separate xml (tablet_shortterm_column.xml) see above.
Anyway, it seems logcat complains that rlo_shortterm_col already has a parent, so it won't allow an another ptr_rlo_rght_middle.addView(rlo_shortterm_col ). Makes no sense.
I spent so many hours on thsi problem and still can't solve it. Can someone please give me a hand? Thanks in advance.
I have an xml file (tablet_shortterm_column.xml) that contains a RelativeLayout that I need to re-use, again and again. Sometimes many times on the same screen stacked one after the other horizontally. I am attempting to insert one into an existing RelativeLayout (ie. one inside the other.)
//exerpts
public class TabletMain extends Activity {
setContentView(R.layout.tablet_main);
public RelativeLayout ptr_rlo_rght_middle;
ptr_rlo_rght_middle = (RelativeLayout) findViewById(R.id.rlo_rght_middle);
//rlo_rght_middle is in tablet_main.xml
LayoutInflater inflater =
(LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View llo_tmp = (View) inflater.inflate(R.layout.tablet_shortterm_column,null);
RelativeLayout rlo_tmp = (RelativeLayout) llo_tmp.findViewById(R.id.rlo_shortterm_col);
// rlo_shortterm_col is the object I want to reuse it a RelativeLayout and is inside
// tablet_shortterm_column.xml
RelativeLayout.LayoutParams rlo_layoutparams;
rlo_layoutparams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
rlo_layoutparams.addRule(RelativeLayout.RIGHT_OF, R.id.llo_rght_middle_col1);
// llo_rght_middle_col1 is a RelativeLayout inside tablet_main.xml,
// I want to put another RelativeLayout view right next to it.
rlo_tmp.setLayoutParams(rlo_layoutparams);
ptr_rlo_rght_middle.addView(rlo_tmp); //Application crashes right on this line.
} //end Activity
//********************* content of tablet_shortterm_column.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:id="#+id/rlo_shortterm_col"
android:layout_width="180dp"
android:layout_height="fill_parent"
android:background="#436699"
android:orientation="vertical"
android:layout_margin="3px"
android:weightSum="1"
> <!-- android:background="#32CD32" android:layout_height="365dp" android:layout_margin="30px" -->
<Button
android:id="#+id/btn_shortterm_col"
android:layout_alignParentTop="true"
android:text="Tuesday Afternoon"
android:layout_margin="15px"
android:textSize="12px"
android:textColor="#FFFFFF"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#296699"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
> <!--android:background="#32CD32" -->
</Button>
<ImageView
android:id="#+id/iv_shortterm_col"
android:layout_below="#+id/btn_shortterm_col"
android:src="#drawable/tblet_icon14_med"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
><!-- android:src="#drawable/tblet_shape1" android:layout_gravity="center_horizontal" -->
</ImageView>
<TextView
android:id="#+id/tv_shortterm_col1"
android:layout_below="#+id/iv_shortterm_col"
android:text="-10ÂșC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10px"
android:background="#DCDCDC"
android:textColor="#000000"
android:textSize="12px"
android:layout_centerHorizontal="true"
> <!-- android:layout_gravity="center_horizontal" -->
</TextView>
<TextView
android:id="#+id/tv_shortterm_col2"
android:layout_below="#+id/tv_shortterm_col1"
android:text="Flurries"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10px"
android:background="#DCDCDC"
android:textColor="#000000"
android:textSize="12px"
android:layout_centerHorizontal="true"
>
</TextView>
<RelativeLayout
android:id="#+id/rlo_shortterm_col_1"
android:layout_below="#+id/tv_shortterm_col2"
android:src="#drawable/tblet_shape2"
android:background="#32CD32"
android:layout_height="113dp"
android:layout_margin="40px"
android:layout_width="125dp"
> <!--android:background="#32CD32" android:orientation="vertical" -->
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Create a separate xml file for your RelativeLayout and then inflate it as many times as you want.
llo_tmp is the parent view of the RelativeLayout you're trying to reuse. Thus, you can't add it to another ViewGroup and you get that logcat error.
You can remove the LinearLayout stuff from your xml file and inflate the xml file in the same way (though maybe instead of returned View you'd return a RelativeLayout). You shouldn't have to change much of the java code since the reference is still the same.
Or, a quick fix may be to add llo_tmp to your ViewGroup instead of rlo_tmp. Either way, rlo_tmp already has a parent and can't be reused. Since you don't have your layout fill the entire screen width, you probably don't want this.