Issue
PFB my layout
My listView does not get scrolled I have 3 list below one relative layout Its the structure that like when I click on Relative Layout The list gets visible . Its working fine when I click on relative layout and after the data is populated . But the list does not seem to scroll.
<ScrollView
android:layout_width="match_parent"
android:layout_height="580dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/bg_box"
android:orientation="vertical"
android:padding="20dp" >
<RelativeLayout
android:id="@+id/landrel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bar" >
<TextView
android:id="@+id/landHoldingtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="63dp"
android:text="LAND HOLDING : 0 LAND"
android:textColor="#FFFFFF" />
<ImageView
android:id="@+id/arrowLandHolding"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignRight="@+id/landHoldingtext"
android:layout_marginRight="50dp"
android:layout_marginTop="24dp"
android:src="@drawable/up_aarow" />
</RelativeLayout>
<ListView
android:id="@+id/landHoldingList"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" >
</ListView>
<RelativeLayout
android:id="@+id/familyrel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/bar" >
<TextView
android:id="@+id/familyDetailstext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="63dp"
android:text="FAMILY DETAILS : 0 MEMEBER"
android:textColor="#FFFFFF" />
<ImageView
android:id="@+id/arrowFamily"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignRight="@+id/familyDetailstext"
android:layout_marginRight="50dp"
android:layout_marginTop="24dp"
android:src="@drawable/up_aarow" />
</RelativeLayout>
<ListView
android:id="@+id/familyDetailsList"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" >
</ListView>
<RelativeLayout
android:id="@+id/bankrel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/bar" >
<TextView
android:id="@+id/bankDetailstext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="63dp"
android:text="BANK DETAILS "
android:textColor="#FFFFFF" />
<ImageView
android:id="@+id/arrowBank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignRight="@+id/bankDetailstext"
android:layout_marginRight="50dp"
android:layout_marginTop="24dp"
android:src="@drawable/up_aarow" />
</RelativeLayout>
<ListView
android:id="@+id/bankDetailsList"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" >
</ListView>
<RelativeLayout
android:id="@+id/otherrel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/bar" >
<TextView
android:id="@+id/otherDetailsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="63dp"
android:text="OTHER DETAILS "
android:textColor="#FFFFFF" />
<ImageView
android:id="@+id/arrowOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignRight="@+id/otherDetailsText"
android:layout_marginRight="50dp"
android:layout_marginTop="24dp"
android:src="@drawable/up_aarow" />
</RelativeLayout>
<ListView
android:id="@+id/otherDetailsList"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/aadharCardImgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:src="@drawable/aadhar_card_butt_copy" />
<TextView
android:id="@+id/aadharCardTxtView"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aadhar Card" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:id="@+id/passbookImgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:src="@drawable/passbook_butt" />
<TextView
android:id="@+id/passbookTxtView"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Passbook" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
My Adapter Layout
<?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:background="@drawable/field_bar_bg"
android:weightSum="6"
android:orientation="horizontal" >
<TextView
android:paddingTop="25dp"
android:id="@+id/RSnumberTxt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="126/1" />
<TextView
android:id="@+id/type"
android:paddingTop="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="Oil Palm" />
<TextView
android:id="@+id/year"
android:paddingTop="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="2007-08" />
<ImageView
android:id="@+id/visitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/visit_button" />
<ImageView
android:id="@+id/yieldButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/yield_button" />
<ImageView
android:id="@+id/landButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/land_button" />
</LinearLayout>
Solution
The reason behind that it - Your listview is inside ScrollView
Do as following to fix your trouble -
ListView lv = (ListView)findViewById(R.id.landHoldingList); // your listview inside scrollview
lv.setOnTouchListener(new ListView.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle ListView touch events.
v.onTouchEvent(event);
return true;
}
});
What this does is disable the TouchEvents on the ScrollView and make the ListView intercept them. It is simple and works all the time.
Answered By - Narendra Singh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.