该方法findViewById(INT)是未定义的类型 [英] The method findViewById(int) is undefined for the type

查看:787
本文介绍了该方法findViewById(INT)是未定义的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的错误

该方法findViewById(INT)是未定义的类型PM_section

The method findViewById(int) is undefined for the type PM_section

想实现我的可扩展的ListView的时候。我相信这是一个常见的​​错误,但我无法找到一个解决方案。我试图学习片段和这样的,它一直是一场艰苦的战斗自从我开始。我已经做搜索的公平一点,并发现了很多成绩,好像没有帮我在我的情况的。

when trying to implement my Expandable ListView. I am sure this is a common error, but I am having trouble finding a solution. I am attempting to learn fragments and such, and it has been an uphill battle ever since I started. I have done a fair bit of searching, and found a lot of results, that don't seem to help me in my case.

如果有人能够给我任何见解,或指明了正确的方向,我将不胜AP preciate吧。

If someone could give me any insight, or point me in the right direction I would greatly appreciate it.

我的小测试类低于

public class PM_section extends Fragment {
//  CustomExpListView custExpListView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        View V = inflater.inflate(R.layout.fragment_pm_section_test, container, false);

        CustomExpListView custExpListView = (CustomExpListView)
                this.findViewById(R.id.ExpandableListView01);
        return V;   
    }// end on create
}

在CustomExpListView类是pretty的很多副本,从Android示例项目粘贴,并且是快乐的,没有问题。

The CustomExpListView class was pretty much copy, pasted from the Android Sample Projects, and is happy and has no problems.

感谢您帮助我。

推荐答案

如果 R.id.ExpandableListView01 是一部分 R.layout.fragment_pm_section_test ,然后替换 V

If R.id.ExpandableListView01 is part of R.layout.fragment_pm_section_test, then replace this with V.

CustomExpListView custExpListView = (CustomExpListView)
                V.findViewById(R.id.ExpandableListView01);

片段■不要有 findViewById()方法。您需要使用您的充气查看,而不是把一切都从你的布局。

Fragments do not have a findViewById() method. You need to use your inflated View instead to get everything from your layout.

也可以考虑使用Java命名约定。变量以小写字母开头,而类开始大写字母。

Also consider using Java naming conventions. Variables start with lowercase letters while Classes start with Uppercase letters.

这篇关于该方法findViewById(INT)是未定义的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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