一个继承GridView的子类无法显示数据的问题

 

定义了一个类

 

public class AppsDragDemo extends GridView

 

然后在一个layout xml使用这个类

 

<?xml version="1.0" encoding="utf-8"?>

<com.access.thumbhome.DragLayer
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:id="@+id/drag_layer">
   
    <!-- All applications on the top side of the screen -->
        <com.access.thumbhome.AppsDragDemo
            android:id="@+id/appsgrid_fordrag"
            android:tag="all_apps_fordrag"
            android:background="@drawable/application_background"
            android:persistentDrawingCache="animation|scrolling"
            android:alwaysDrawnWithCache="true" android:scrollbars="none"
            android:drawSelectorOnTop="false" android:listSelector="@drawable/grid_selector"
            android:numColumns="auto_fit" android:columnWidth="60dp"
            android:stretchMode="spacingWidth" android:layout_weight="1.0"
            android:layout_height="match_parent" android:layout_width="match_parent"
            android:stackFromBottom="false" android:visibility="visible" />

</com.access.thumbhome.DragLayer>

 

发现使用这个类生成的GridView无法显示数据。花了很长时间也没有找到问题,后来瞥见一段代码

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        // TODO Auto-generated method stub
       
    }

 

不知道什么时候重载了这个函数,而这个函数什么都不干,也就是这个空函数把父类的关键方法给替换了,所以,这个GridView没法显示数据。加上下面的一行可以解决问题,或者把这个重载函数删除,反正是没有用的。

 

super.onLayout(changed, l, t, r, b);

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值