androidexpandablelistviewconvertview

Cannot resolve symbol "ConvertView"


I'm following this tutorial to implement Expandable ListView: https://www.youtube.com/watch?v=GD_U0-N3zUI&t=404s I did everything same as in it, But:

@Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        String title=(String)this.getGroup(i);
        if(convertView==null){
            LayoutInflater layoutInflater=(LayoutInflater)this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView=layoutInflater.inflate(R.layout.parent);

        }
        return null;
    }

I'm getting this error: "Cannot resolve symbol convertView"

Tried: enter image description here


Solution

  • I did everything same as in it

    No you didn't. If you watch the video closely you will notice the parameter names are different in the video.

    I'm getting this error: "Cannot resolve symbol convertView"

    That is because convertView is not defined in your code. (in the video it is).

    You can fix it by either changing the parameter names:

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
    

    The key here (for your problem) is the third parameter View convertView.

    The other option is to use the your variable name view everywhere convertView is used.

    Update: the inflate function expects a layout resource id (e.g. R.layout.parent an a corresponding XML file should exist in the rea/layout folder) as the first parameter. You are passing an ID resource.