Is it impossible to add multiple views to a ScrollView? - android

If so, it seems that either the ScrollView is rather lame (doubtful) or there's some other way to do it. Here's my code. Where it bombs (the second time through the loop, that is) is commented.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ondemandandautomatic_dynamicauthorize);
ScrollView svh = (ScrollView) findViewById(R.id.scrollViewHost);
// Contacts data snippet adapted from
// http://saigeethamn.blogspot.com/2011/05/contacts-api-20-and-above-android.html
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur
.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// Create a Linear Layout for each contact?
LinearLayout llay = new LinearLayout(this);
llay.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.weight = 1.0f;
CheckBox cbOnDemand = new CheckBox(getApplicationContext());
cbOnDemand.setTag(id);
cbOnDemand.setLayoutParams(llp);
llay.addView(cbOnDemand);
CheckBox cbTime = new CheckBox(getApplicationContext());
cbOnDemand.setTag(id);
cbTime.setLayoutParams(llp);
llay.addView(cbTime);
CheckBox cbSpace = new CheckBox(getApplicationContext());
cbOnDemand.setTag(id);
cbSpace.setLayoutParams(llp);
llay.addView(cbSpace);
TextView tv = new TextView(getApplicationContext());
tv.setTag(id);
tv.setText(name);
tv.setLayoutParams(llp);
llay.addView(tv);
svh.addView(llay); // it transports me to Eclipse's Debug perspective when I hit this line the SECOND time around.
// One cat on stackOverflow said to do this, another said it
// would be unnecessary
svh.invalidate();
}
}
}

There are two things you can do to solve this.
1) Make the only child of the ScrollView be a vertical LinearLayout and add all of your children to the LinearLayout instead of the ScrollView.
2) A preferable alternative would be to use a ListView (which is probably implemented using a LinearLayout inside of a ScrollView).

Only one view can be included in a ScrollView. However, that view could be a layout, like a LinearLayout. Typically what I do is add such a view to a ScrollView, and it works great.
Example:
<ScrollView>
<LinearLayout>
<ImageView/>
<TextView/>
</LinearLayout>
</ScrollView>

Nested Scroll view hold only one direct view as child if you wants to add more then you have to include just one view child as view group like linear layout,that it can hold more views,as you can add buttons etc.. in other words so view group can hold multiple views if you put them as child view of NestedScrollView. i include a layout as child of NestedScrollView and its further have many views.
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<include layout="#layout/descriptioncontent_layout" />
</android.support.v4.widget.NestedScrollView>
add multiple items to description content_layout ...etc.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
card_view:cardCornerRadius="5dp">
<include layout="#layout/descption_layout" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
card_view:cardCornerRadius="5dp">
<include layout="#layout/howtodoit" />
</android.support.v7.widget.CardView>
Description_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Full Body:"
android:id="#+id/description"
android:textSize="20sp"
android:textColor="#color/how"
android:padding="10dp"
android:layout_marginLeft="10dp"
android:layout_gravity="center|left" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="If you are brand new to yoga, there are certain postures that are essential for you to learn so you can feel comfortable in a class or practicing on your own at home"
android:id="#+id/detaildescription"
android:textSize="18sp"
android:padding="10dp"
android:layout_gravity="center_horizontal" />

Related

Layout weight not working as intended

I have a slight problem getting my layout_weight to work. I am creating a custom bottomBar. But i cant make it to stretch as i want it to.
Bottom Bar View
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottom_bar_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/bottom_bar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:orientation="horizontal"/>
</RelativeLayout>
This is the big container i am adding my buttons (items) to.
Bottom Bar Item
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/bottom_bar_item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/arrow_up_float"/>
<TextView
android:id="#+id/bottom_bar_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXT"/>
</LinearLayout>
This is my items that i add dynamically to the view. But somehow the view is not stretched properly.
But when i hardcode it in. It works. So could it be that layout weight does not work dynamically?
How i add the views (items)
private void updateItems(final List<BottomBarTab> bottomBarTabs) {
if (bottomBarTabs.size() < TABS_COUNT) {
throw new RuntimeException("Not enough buttons for bottomBar");
}
for (int i = 0; i < TABS_COUNT; i++) {
bottomBarTabs.get(i).setOnClickListener(this);
bottomBarTabs.get(i).prepareLayout();
container.addView(bottomBarTabs.get(i));
}
}
Screenshot
LayoutWeight is given to inner components of layout only not on parent Linearlayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:weightSum="2">
<android.support.v7.widget.AppCompatImageView
android:id="#+id/bottom_bar_item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#android:drawable/arrow_up_float"/>
<TextView
android:id="#+id/bottom_bar_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TEXT"/>
</LinearLayout>
public void prepareLayout() {
View view = inflate(getContext(), R.layout.bottom_bar_item,this);
LinearLayout.LayoutParams params =
new LayoutParams(0,LayoutParams.MATCH_PARENT,LAYOUT_WEIGHT);
view.setLayoutParams(params);
if(backgroundColor != null) {
view.setBackgroundColor(backgroundColor);
}
TextView titleText = (TextView) view.findViewById(R.id.bottom_bar_item_text);
titleText.setText(title);
AppCompatImageView imageView = (AppCompatImageView) view.findViewById(R.id.bottom_bar_item_icon);
imageView.setImageResource(iconResId);
}
I changed in my prepareLayout function and put new layoutParams. Because somehow after inflation. The view ignores the weight that was set to it. So i had to force it by code. Maybe this is a android bug?

Top view disappeared in ScrollView

I am adding list of table layouts to a LinearLayout dynamically. For that I used ScrollView to see the list of tables which are added to linear layout.
below is my xml code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:background="#color/white"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RET MASTER SITE REPORTS"
android:paddingBottom="5dp"
android:textColor="#android:color/black"
android:textStyle="bold" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"></LinearLayout>
</ScrollView>
Source code:
layout = (LinearLayout) findViewById(R.id.linearLayout);
for (int i = 0; i < 5; i++) {
if (isColorChange) {
displayDeviceDetails(getColor(R.color.blue), getColor(R.color.lightBlue));
} else {
displayDeviceDetails(getColor(R.color.orange), getColor(R.color.lightOrange));
}
}
//Method which i am calling from loop
private void displayDeviceDetails(int titleColor, int cellColor) {
TableRow row = null;
TableLayout tableLayout = new TableLayout(this);
tableLayout.setPadding(0, 30, 0, 0);
for (int i = 0; i < arr.length; i++) {
row = (TableRow) inflater.inflate(R.layout.child_views, null);
row.setBackgroundColor(titleColor);
TextView tvTitle = (TextView) row.findViewById(R.id.tvRowTitle);
TextView tvText = (TextView) row.findViewById(R.id.tvRowText);
if (i == 0) {
tvText.setVisibility(View.GONE);
tvTitle.setGravity(Gravity.CENTER);
tvTitle.setTextColor(Color.WHITE);
tvTitle.setText(arr[i]);
} else {
changeBgColor(cellColor);
setBgColor(tvTitle);
setBgColor(tvText);
tvTitle.setGravity(Gravity.RIGHT);
tvTitle.setText(arr[i]);
tvText.setText(arr1[i]);
row.setBackgroundColor(titleColor);
}
tableLayout.addView(row);
}
layout.addView(tableLayout);
}
In the above code, There is TextView at top of the screen which is used to display some text. I added 3 tables to a linear layout it's showing 1st table from middle followed by next 2 tables with some white space/empty screen at bottom. If I increase number of tables that bottom screen empty space is increasing.
Example: There are 5 tables in a ScrollView, but it will display from 2nd table that might be from table starting or might be from middle of the table, followed by 3rd, 4th n 5th tables with empty space at bottom of the ScrollView.
I can able to see the Text, but I added 5 tables to linear layout inside ScrollView, when I executed that, it will display from 2nd table that might be from table starting or might be from middle, followed by 3rd, 4th n 5th tables with empty space. I have attachment my screen-shots.
Please help me.
Found it ! It's the android:layout_gravity="center_vertical" in the LinearLayout that is the culprit..
Just delete this and everything should be fine.
You need to change the root LinearLayout to RelativeLayout as below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:background="#color/white"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RET MASTER SITE REPORTS"
android:paddingBottom="5dp"
android:textColor="#android:color/black"
android:textStyle="bold" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/textView">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>
</ScrollView>
</RelativeLayout>
I hope this helps you

Xamarin Android Table Layout

Here is a cut-down version of the table layout im using. I'm trying to simulate a HTML percentage width by using a weightSum of 100 on the table and applying layout_weight on each view appropriately.
From my C# code I'm then looking to add each line item dynamically as new TableRow to the table layout. I can't seem to figure out how to ensure that the columns line up in the new rows. This is different to HTML, where columns are always the same width per row.
I've been messing around LayoutParameters to try and set a weight, but doesn't seem possible on a textview.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/pagetemplate">
<TableLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px"
android:weightSum="100"
android:id="#+id/idBasketTable"
style="#style/pagetemplate">
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="Options"
android:visibility="invisible" />
<TextView
android:text="Product Name"
style="#style/textViewHeader"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_weight="30"
android:layout_height="wrap_content" />
<TextView
android:text="Qty"
style="#style/textViewHeader"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_weight="30"
android:layout_height="wrap_content" />
<TextView
android:text="Price"
style="#style/textViewHeader"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_weight="30"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
<include
layout="#layout/Menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Then from my code I'm attempting something similar to this (cut down for simplicity). You'll notice my attempted LayoutParameter code commented out on each View as this was making them disappear all together from the layout. Not sure whether I should be concentrating on the layout styles of the row itself or the individual views?
Secondly, in the first row, I've tried to create a column that has no title. The line item rows will include a small delete button here, which is why I've tried to make an empty column. Is there a better way to do this rather than creating a textView (used for nothing) and setting to invisible?
TableLayout tl = (TableLayout)FindViewById(Resource.Id.idBasketTable);
TableRow tr = new TableRow(this)
{
LayoutParameters = new TableRow.LayoutParams(TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.MatchParent, 100)
};
TextView tv_ProductName = new TextView(this)
{
Text = item.ItemName//,
// LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent,ViewGroup.LayoutParams.WrapContent)
};
tv_ProductName.SetTextAppearance(this, Resource.Style.textViewDetail);
TextView tv_Qty = new TextView(this)
{
Text = item.ItemQty.ToString()//,
// LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)
};
tv_Qty.SetTextAppearance(this, Resource.Style.textViewDetail);
TextView tv_Price = new TextView(this)
{
Text = item.ItemPrice.ToString()//,
// LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)
};
tv_Price.SetTextAppearance(this, Resource.Style.textViewDetail);
ImageButton ib_Delete = new ImageButton(this)
{
// LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent,ViewGroup.LayoutParams.WrapContent)
};
//set the view values for the current row.
ib_Delete.SetImageResource(Resource.Drawable.deleteitem);
Guid itemID = item.ItemID;
//assign the delete onclick event.
ib_Delete.Click += delegate
{
deleteItem_OnClick(ib_Delete, itemID);
};
//add views to the row.
tr.AddView(ib_Delete);
tr.AddView(tv_ProductName);
tr.AddView(tv_Qty);
tr.AddView(tv_Price);
//add the row to the table layout.
tl.AddView(tr);
Hope this all makes sense, appreciate the feedback :)

Layouttrouble extending tablerow and inflating xml tablerow

I'm pretty close to go for a LinearLayout alternative, but its kind of irritating not getting this right. To get most flexibility out of things I've defined a TableLayout xml with only a row header defined. Next I've generated a seperate TableRow xml defining the "row template". In Javacode I've subclassed TableRow and in the constructor i inflate the tablerow template to attach to the root (the subclassed class).
Well, good so far. When the table is populated the headerrow is ok, but the other rows are NOT. It seems like they are laid out in a different way, the two columns is not filling the whole width as expected and the the coluomns is therefore not aligned correctly to each other.
Anyone who can shed some light on this one? I've tried a lot of solutions, but nothing makes it work.
The tablelayout with header row
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<TableLayout
android:id="#+id/zone_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:clipToPadding="false" >
<TextView
android:layout_width="0dip"
android:layout_weight="0.8"
android:background="#ffcccccc"
android:text="Zonename"
android:textColor="#android:color/black" />
<TextView
android:layout_width="0dip"
android:layout_weight="0.2"
android:background="#ffcccc00"
android:gravity="right"
android:text="Antall"
android:textColor="#android:color/black" />
</TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
The "other" inflated row
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/zonetablerow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/zonerow_name"
android:layout_width="0dip"
android:layout_weight="0.8"
android:background="#ffcccccc"
android:textSize="18dp" />
<TextView
android:id="#+id/zonerow_invcount"
android:layout_width="0dip"
android:layout_gravity="right"
android:layout_weight="0.2"
android:background="#ffcccc00"
android:textSize="18dp" />
</TableRow>
Class extending TableRow
public class ZoneRow extends TableRow {
private ZoneInventoryDAO dao = null;
private int inventoryCount = 0;
public ZoneRow(Context ctx, ZoneInventoryDAO dao) {
this(ctx, dao, 0);
}
public ZoneRow(Context ctx, ZoneInventoryDAO dao, int inventoryCount) {
super(ctx);
setWeightSum(1.0f);
this.dao = dao;
this.inventoryCount = inventoryCount;
doLayout();
}
private void doLayout() {
// XML layouten settes med zonerow som parent (se:
// http://developer.android.com/resources/articles/layout-tricks-merge.html)
View v = LayoutInflater.from(getContext()).inflate(R.layout.zonerow,
this, true);
TextView t = (TextView) findViewById(R.id.zonerow_name);
TextView cnt = (TextView) findViewById(R.id.zonerow_invcount);
t.setText(dao.getZoneAlias());
cnt.setText(String.valueOf(inventoryCount));
}
public void incInventory() {
inventoryCount++;
}
public ZoneInventoryDAO getDAO() {
return dao;
}
}
What it looks like is that you are extending tablerow and creating an instance of that object. This will cause a table row to be created. Then you are inflating another tablerow which is for some reason interacting with the first. For a quick fix try adding something like table.setColumnStretchable(0, true);
I'm having the same problem. I fixed it by not doing that - specifically by not subclassing TableRow, but just instantiating them in code and applying whatever I needed to them by hand. You can do this by encapsulating instead. Have some record that has ZoneInventoryDAO, inventoryCount, and tableRow, which points to the corresponding TableRow instance. Just instantiate TableRow with an inflation:
TableLayout table = (TableLayout) inflater.inflate(R.layout.my_table, null); // etc
...
for (//each data item//) {
TableRow tr = (TableRow) inflater.inflate(R.layout.my_table_row, null);
TextView tv1 = (TextView) findViewById(R.id.table_entry_1);
tv1.setText("Whatever goes here");
...
// and so on for each column
table.addView(tr);
}
The above worked for me when moving that same code into a class which extends TableRow did not.
I know this is old, but I had same issue, and figured it out, so maybe this will help future users.
The problem is, that when you inflate the TableRow from XML, and you add it ino your extended TableRow, it is seen by the Table as a single column, with multiple children, as the TableRow in your Layout is in essence a ViewGroup. Therefore it lays out the table, as a single column table.
The solution is that in the TableRow XML layout, use a <merge> type, rather than a <TableRow> type. This way when inflated, the items within your xml, will be merged into your extended TableRow, and your extended TableRow will have multiple colums.
Here is the example code
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/zonetablerow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/zonerow_name"
android:layout_width="0dip"
android:layout_weight="0.8"
android:background="#ffcccccc"
android:textSize="18dp" />
<TextView
android:id="#+id/zonerow_invcount"
android:layout_width="0dip"
android:layout_gravity="right"
android:layout_weight="0.2"
android:background="#ffcccc00"
android:textSize="18dp" />
</merge>

Add different TextViews to ScrollView

I Have activity that get some data from the internet, and shows it to the screen.
I'm using scroll view cause it's long text, I also want different text style for a different data,so I use few textViews with a different style and to show it on the Activity screen,
my problem is that scroll view can handle only one view, so how can I use scrolling to show different style of Text view, I tried to add LinearLayout to the scrollView and add all the textViews dynamically in code to this LinearLayout ,but I'm getting exception - scroll view can host only one direct child.
The code below:
/** this is the function, which called from the onClick method.
wanted data object contains 2 strings title message and the message itself.
When debug the code i can see that there's two String values in each loop.
but i cant add the linearLayout to my scrollView - exception ScrollView can host only one direct child */
private void showResult(ArrayList<WantedData> result) {
// TODO Auto-generated method stub
TextView title;
TextView data;
scrollLayout = (LinearLayout) findViewById(R.id.LlScrollView);
for (WantedData curr : result) {
if (curr.getTitle() == null) {
break;
}
title = new TextView(this);
title.setText(curr.getTitle());
scrollLayout.addView(title, LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
data = new TextView(this);
data.setText(curr.getData());
scrollLayout.addView(data, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
}
scroll.addView(scrollLayout, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
//at the onCreate method - scroll = (ScrollView) findViewById(R.id.SvShowTextFromServer);
}
the xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include
android:id="#+id/layout_reffernce"
layout="#layout/explore" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter City" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/EtCity"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_weight="0.14"
android:orientation="vertical" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bSearchCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Enter State" />
<EditText
android:id="#+id/EtState"
android:layout_width="253dp"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
<ScrollView
android:id="#+id/SvShowTextFromServer"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/LlScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/backround"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
The problem is double creating of container in ScrollView. You should not create it in activity, but take already defined from xml:
LinearLayout scrollContainer = (LinearLayout)findViewById(R.id.LlScrollView);
for (...) {
//create here some text
scrollLayout.addView(text);
}
If you have defined a LinearLayout in XML you don't have to create a new LinearLayout in your code but you have to retrieve the existing one in this way
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.LlScrollView);
Otherwise you have to remove the LinearLayout in your XML and add all by code.

Categories

Resources