So I have a class that gets items from a database and then places them into a layout and inflates. This loops through each item in the database inflating a new layout for each item. This eventually extends past the viewport and will need a scroll bar which I assume will be a ScrollView. I’ve tried many different ways and can’t get it to scroll through the entire content. Please advise.
Java:
View myView = linflater.inflate(R.layout.myviews, null);
TextView tvQuote = (TextView) myView.findViewById(R.id.lblQuote);
//Set an id to know which quote is in use
tvQuote.setId(i);
TextView tvShared = (TextView) myView.findViewById(R.id.lblShared);
TextView tvSaid = (TextView) myView.findViewById(R.id.lblSaid);
//Change name dynamically
tvQuote.setText((strQuote).toString());
tvShared.setText(("Shared by: " + strFName + " " + strLInitial).toString());
tvSaid.setText(("Said by: " + strFNameSaid + " " + strLInitialSaid).toString());
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:id="@+id/myMainLayout"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content">
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Quoter"
android:id="@+id/lblTitle"
android:textSize="16px"
android:padding="5px"
android:textStyle="bold"
android:gravity="center_horizontal">
</TextView>
</LinearLayout>
myviews.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/lblQuote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/lblShared"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/lblSaid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:text=" "
android:textSize="1pt"
android:background="#6F7285"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
What would be the best solution to scroll through all of these inflated layouts?
I actually found that adding the ScrollView to the main.xml was the fix. Thanks for all your help though guys. I’d still like to know if I am doing this wrong though.