小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

GridView中設(shè)置了Button以后就不能響應(yīng)OnItemClick()

 點(diǎn)點(diǎn)滴滴 2012-08-30

[Android UI界面] GridView中設(shè)置了Button以后就不能響應(yīng)OnItemClick()


1
當(dāng) 我們?cè)贕ridView或者ListView里面設(shè)置了Textiew的時(shí)候,假如我們不給Textiew設(shè)置onlick()的話,那么Gridiew 的OnItemClick()就是可以執(zhí)行的,但是當(dāng)把TextView換成是Button的時(shí)候我們也不設(shè)置onClick()的話,GridView 的OnItemClick()也是不能執(zhí)行的,為什么呢,這說(shuō)明Button和TextView內(nèi)部事件方面有區(qū)別,去查看Button的源代碼,代碼很 少就這么幾句
public class Button extends TextView {
    public Button(Context context) {
        this(context, null);
    }

    public Button(Context context, AttributeSet attrs) {
        this(context, attrs, com.android.internal.R.attr.buttonStyle);
    }

    public Button(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
所以,主要的貓膩還是在com.android.internal.R.attr.buttonStyle這個(gè)里面,查看這個(gè)xml文件,Button設(shè)置多了兩個(gè)屬性如下:
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
所以我們要在代碼里面把這兩個(gè)屬性設(shè)為false,這樣就可以響應(yīng)GridView的onItemClick方法了,但是一定要注意,不管是 Button,還是TextView,只要設(shè)置了onClick() 的話,那么OnItemClick()就不會(huì)被執(zhí)行(以上的內(nèi)容都是基于一個(gè)GridView或者是ListView的每個(gè)Item只有一項(xiàng),要不是 Button,要不是TextView,不是這種情況的,上面的就只能參考一下了)

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多