ListView double-Nested processing

Source: Internet
Author: User

Today in the project process encountered in the ListView item needs to use the ListView to show the processed content, and then encountered a very headache problem, as item of the ListView can not slide, and display is not normal, just display a few sub item. The child item can not be displayed all, but sometimes we want to make the ListView as item do not show all, but can slide, to solve this problem need to understand the android on the distribution mechanism of events, my solution is to integrate the ListView, Override Intercepttouchevent to return false to suppress the interception of touch events by the parent ListView and distribute the touch events to Child view for processing. Then, when used, use it as a parent ListView so that the child ListView can slide.

          

1234567891011121314151617181920212223242526272829303132333435363738 public class ParentListView extends ListView {public ParentListView(Context context) {super(context);// TODO Auto-generated constructor stub}public ParentListView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);// TODO Auto-generated constructor stub}public ParentListView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}//将 onInterceptTouchEvent的返回值设置为false,取消其对触摸事件的处理,将事件分发给子view@Overridepublic boolean onInterceptTouchEvent(MotionEvent ev) {// TODO Auto-generated method stubreturn false; }}

1234567891011121314 <?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" ><!-- 这里做demo用,直接使用了android中的ListActivity-->    <i.test.ParentListView android:id=" @android :id/list"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:dividerHeight="2dip"        android:scrollbars="none"        /></LinearLayout>

ListView double-Nested processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.