为什么函数getChildCount()总是在onCreate()中返回0 [英] why the function getChildCount () always return 0 in onCreate()

查看:366
本文介绍了为什么函数getChildCount()总是在onCreate()中返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

i用GridView创建了一个示例项目。

显示GridView项目后,我想在cliked这个项目时改变背景颜色。

所以,事件点击项目,我可以做...

但是,更改背景还没有....

i已将此功能移至onPause(),它有效,但它不是一个好的解决方案

你可以帮助我...



hi all!
i have create a sample project with GridView.
after show items of GridView, i want to change background color when cliked this item.
so, event click on item, i can do...
but, change background is not yet....
i have move this function to onPause() , it's worked, but it's not a good solution
can you help me...

for(int i=0; i<((ViewGroup)v).getChildCount(); ++i) {
    View nextChild = ((ViewGroup)v).getChildAt(i);
}

推荐答案

gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
 
               //implement your code here
            }
        });


这篇关于为什么函数getChildCount()总是在onCreate()中返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆