List of Views in LinearLayout inside ScrollView



I'm trying to add two lists into a ScrollView and I've recently read that you shouldn't put ListViews inside a ScrollView. So I decided to try using two LinearLayouts and dynamically adding inflated views to them. Unfortunately all I'm seeing is the two text views I'm using as titles but no Linear Layouts. :/ Could someone please explain why my LinearLayouts are not not showing?


Layout Inflation:



ArrayList<JSONObject> sightList = new ArrayList<JSONObject>();
try{
JSONObject obj = new JSONObject(loadJSONFromAsset());
JSONArray m_jArry = obj.getJSONArray("Locations");

for (int i = 0; i < m_jArry.length(); i++)
{
JSONObject jo_inside = m_jArry.getJSONObject(i);
if ("Food & Drink".equals(jo_inside.getString("Section")))
{
sightList.add(jo_inside);
}
}
}
catch (Exception e) {}
sort(sightList);

LinearLayout discounts = (LinearLayout) findViewById(R.id.discount_list);
LinearLayout others = (LinearLayout) findViewById(R.id.other_list);

for (int i = 0; i < sightList.size(); i++)
{
JSONObject j = sightList.get(i);
try {
View v = getLayoutInflater().inflate(R.layout.next_list_item, null);
v.setId(i);
TextView title = (TextView) v.findViewById(R.id.title);
TextView subtitle = (TextView) v.findViewById(R.id.subtitle);
title.setText(j.getString("name"));
title.setTypeface(montserrat);
subtitle.setText(j.getString("TypeOfR"));
subtitle.setTypeface(montserrat);

if (j.getBoolean("hasDiscount"))
{
discounts.addView(v);
}
else
{
title.setTextColor(Color.BLACK);
others.addView(v);
}
} catch (JSONException e) {
e.printStackTrace();
}
}


Activity Layout:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:id="@+id/featured"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="@string/featured"
android:src="@drawable/bandus"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>

<ScrollView
android:id="@+id/next_info_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/featured">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/discounts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:background="@color/list_header"
android:text="@string/food"
android:textColor="@color/header_text"
android:textSize="14sp"/>

<LinearLayout
android:id="@+id/discount_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/discounts"
android:orientation="vertical"/>

<TextView
android:id="@+id/others"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Other Food and Drink"
android:layout_below="@id/discount_list"
android:paddingLeft="8dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:background="@color/list_header"
android:textColor="@color/header_text"
android:textSize="14sp"/>

<LinearLayout
android:id="@+id/other_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/discounts"
android:orientation="vertical"/>

</RelativeLayout>

</ScrollView>

</RelativeLayout>


List Items:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="50dp" >

<RelativeLayout
android:id="@+id/title_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_centerVertical="true">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/badass_blue"
android:textSize="17sp"/>

<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/list_header"
android:textSize="12sp"
android:layout_below="@id/title"/>

</RelativeLayout>

<ImageView
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="@drawable/divider"
android:contentDescription="@string/divider"/>

<ImageView
android:id="@+id/details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:src="@drawable/bluearrow"
android:contentDescription="@string/arrow"
android:layout_marginRight="20dp"/>

</RelativeLayout>


Thanks for the help (sorry for the long post) :)


No comments:

Post a Comment