Reputation: 1686
I have a list view when I populated it with data it doesn't scroll. Why is this happening I think there's no problem with my java code. I think the problem is with my xml. Here's my xml
<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:background="@drawable/bg_main"
tools:context=".IreportMain" >
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="83dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/bg_nav"
android:gravity="top" >
<ImageView
android:id="@+id/Logo1"
android:layout_width="150dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:src="@drawable/img_lamp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_greetings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:singleLine="true"
android:text="Welcome Guest"
android:textColor="@color/black"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="July 2, 2013"
android:textColor="@color/black" />
<Button
android:id="@+id/btn_Logout"
android:layout_width="70dp"
android:layout_height="30dp"
android:text="@string/logout"
android:textColor="#FFFFFF"
android:background="@drawable/selector_button_background"
android:textSize="15sp" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:layout_below="@+id/header"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:id="@+id/Scrollview">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/header2"
android:layout_marginBottom="20dp">
<ImageView
android:id="@+id/btn_iScan"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:clickable="true"
android:src="@drawable/img_ireport_logo" />
<TextView
android:id="@+id/tv_Report"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/btn_iScan"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="@string/report"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="20sp"/>
<TextView
android:id="@+id/tv_Code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/tv_Report"
android:text="TextView"
android:textColor="@color/black"
android:textSize="18sp"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/row1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:layout_below="@+id/header2" >
<TextView
android:id="@+id/tv_Brand"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/brand"
android:textColor="@color/black" />
<TextView
android:id="@+id/tv_InformationType"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:text="@string/information"
android:textColor="@color/black" />
</LinearLayout>
<LinearLayout
android:id="@+id/row2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row1"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:background="@drawable/gradient"
android:layout_marginRight="2dp">
<TextView
android:id="@+DropDownList/tv_SubBrand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/select_brand"
android:textColor="@color/black"
android:textSize="13sp" />
</RelativeLayout>
<Spinner
android:id="@+id/spn_InfoType"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/gradient"
android:layout_marginRight="2dp"
android:layout_marginLeft="2dp"
android:textSize="13sp" />
<!--
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:background="@drawable/gradient"
android:layout_marginLeft="2dp">
<TextView
android:id="@+DropDownList/tv_InformationType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/select_informationtype"
android:textColor="@color/black"
android:textSize="12sp" />
</RelativeLayout>
-->
</LinearLayout>
<LinearLayout
android:id="@+id/row3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row2"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_District"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/district"
android:textColor="@color/black" />
<TextView
android:id="@+id/tv_CustomerSegment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:text="@string/segment"
android:textColor="@color/black" />
</LinearLayout>
<LinearLayout
android:id="@+id/row4"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="@+id/row3"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<Spinner
android:id="@+id/spn_District"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/gradient"
android:layout_marginRight="2dp"
android:textSize="13sp" />
<RelativeLayout
android:id="@+id/relativeLayout4"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:background="@drawable/gradient"
android:layout_marginLeft="2dp">
<TextView
android:id="@+DropDownList/tv_ConsumerSegment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/select_consumersegment"
android:textColor="@color/black"
android:textSize="13sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/row5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row4"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_Province"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/province"
android:textColor="@color/black" />
<TextView
android:id="@+id/tv_DateObserved"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:text="@string/observed"
android:textColor="@color/black"/>
</LinearLayout>
<LinearLayout
android:id="@+id/row6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row5"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_weight="1">
<Spinner
android:id="@+id/spn_Province"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@drawable/gradient"
android:layout_marginRight="2dp"
android:textSize="13sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:layout_marginTop="13dp"
android:layout_marginBottom="7dp">
<CheckBox
android:id="@+id/chk_Competitor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/selector_checkbox"
android:checked="false"
android:focusable="false"
android:paddingRight="10dp"
android:text="@string/competitor"
android:textColor="@color/black"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
<EditText
android:id="@+id/txt_Date"
android:layout_width="match_parent"
android:layout_height="30dp"
android:singleLine="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10"
android:background="@drawable/edittext_bg"
android:editable="false"
android:layout_marginLeft="2dp"
android:paddingLeft="8dp"
android:textSize="13sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/row9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row6"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_Remarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/black"
android:text="@string/remarks" />
<TextView
android:id="@+id/tv_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/row10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row9"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<EditText
android:id="@+id/txt_Remarks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/edittext_bg"
android:ems="10"
android:gravity="top|left"
android:inputType="textMultiLine"
android:lines="3"
android:paddingLeft="3dp"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/row11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row10"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:id="@+id/tv_AttachedFiles"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/black"
android:text="@string/attach"
android:textStyle="bold"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/row12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row11"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:id="@+id/tv_File"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/black"
android:text="@string/file"
android:gravity="center"/>
<TextView
android:id="@+id/tv_Description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textColor="@color/black"
android:text="@string/description"
android:singleLine="false"/>
<TextView
android:id="@+id/tv_UploadedBy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textColor="@color/black"
android:text="@string/uploadedby"
android:singleLine="false" />
<TextView
android:id="@+id/tv_DateUploaded"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textColor="@color/black"
android:text="@string/dateuploaded"
android:singleLine="false" />
<TextView
android:id="@+id/tv_Action"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textColor="@color/black"
android:text="@string/action" />
</LinearLayout>
<LinearLayout
android:id="@+id/row13"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row12"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:paddingTop="5dp">
<!-- MYLISTVIEW THAT DOESN'T SCROLL -->
<ListView
android:id="@+id/lv_AttachedFileData"
android:layout_width="wrap_content"
android:layout_height="147dp"
android:background="@drawable/frame_white_1"
android:cacheColorHint="#00000000"
android:drawSelectorOnTop="false"
android:lines="3"
android:padding="10dp" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/row14"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/row13"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:paddingTop="5dp">
<Button
android:id="@+id/btn_Save"
android:layout_width="70dp"
android:layout_height="35dp"
android:text="@string/save"
android:background="@drawable/selector_button_background"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<Button
android:id="@+id/btn_Submit"
android:layout_width="70dp"
android:layout_height="35dp"
android:text="@string/submit"
android:background="@drawable/selector_button_background"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<Button
android:id="@+id/btn_Cancel"
android:layout_width="70dp"
android:layout_height="35dp"
android:text="@string/cancel"
android:background="@drawable/selector_button_background"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<Button
android:id="@+id/btn_Attach"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginLeft="70dp"
android:text="@string/attach"
android:background="@drawable/selector_button_background"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/bg_nav"
android:layout_below="@+id/row14"
android:layout_marginTop="15dp"
android:layout_gravity="bottom">
<LinearLayout
android:id="@+id/row15"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:id="@+id/tv_help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="@string/help"
android:textColor="@color/black"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_ContactUs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="@string/contactus"
android:textColor="@color/black"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/tv_Copyright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:text="@string/copyright"
android:textColor="@color/black"
android:layout_below="@+id/row15"/>
<TextView
android:id="@+id/tv_Reserved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:text="@string/reserved"
android:textColor="@color/black"
android:layout_below="@+id/tv_Copyright"/>
<TextView
android:id="@+id/tv_Createdby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_Reserved"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:text="@string/createdby"
android:textColor="@color/black" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Any idea will be a great help thanks
Upvotes: 1
Views: 4215
Reputation: 1850
Your ListView parent is ScrollView. So it loss scrolling property. So please remove ScrollView from this xml and after than run it's work fine.
It's better to set diffrent view type inside the ListView Adapter or use the ListView Footer and Header.
Another Way to manage ScrollView inside ListView in android
Also you can use this Method which will fix the issue you are facing with ListView in ScrollView
public static void updateListViewHeight(ListView myListView) {
ListAdapter myListAdapter = myListView.getAdapter();
if (myListAdapter == null) {
return;
}
//get listview height
int totalHeight = 0;
int adapterCount = myListAdapter.getCount()
for (int size = 0; size < adapterCount ; size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
//Change Height of ListView
ViewGroup.LayoutParams params = myListView.getLayoutParams();
params.height = totalHeight + (myListView.getDividerHeight() * (adapterCount - 1));
myListView.setLayoutParams(params);
}
Upvotes: 0
Reputation: 5595
Simply remove the <ScrollView>
.A listview cannot work within a <ScrollView>
Upvotes: 3
Reputation: 1244
I know I'm posting this 2 years after the OP but it might help someone coming across the same problem. I had this problem before and I fixed it using the following in my xml:
<ListView
android:id="@+id/lv_LVID"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout:weight="1">
</ListView>
If it still doesn't scroll, try removing any <ScrollView>
which you might have as an outer layout.
Upvotes: -2