简体   繁体   中英

How to fix Layoutinflator not found error?

I am trying to display a custom list .I am passing a string array to the class customAdapter. when I try to access the getLayoutInflater it is not being recognized? How can I solve this issue

package com.parse.starter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;

public class CustomAdapter extends BaseAdapter {
    ArrayList<String> descriptions;
     public CustomAdapter(final ArrayList<String> description) {
         descriptions=description;    
    }

    @Override
    public int getCount() {

        return descriptions.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {    
       view=getLayotInflater(R.layout.rowcourses,null);   
        return null;
    }
}

here, change this constructor

private Context context;
public CustomAdapter(Context context, final ArrayList<String> description) {
         descriptions=description;  
         context = context;  
    }

and modify this

@Override
    public View getView(int position, View view, ViewGroup parent) {  
   // so you would require an Inflater service which will load/inflate the layout, and to use service,
   // you need to have access to context, which you can get it from the constructor by passing it from your host class.

     LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

              View aView=inflater.inflate(R.layout.rowcourses, parent,false);
  // once you load the view, you need to return that, in your case you were returning null   
                return aView;
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM