Как исправить ошибку Layoutinflator not found?

1

Я пытаюсь отобразить пользовательский список. Я передаю строковый массив в класс customAdapter. когда я пытаюсь получить доступ к getLayoutInflater, он не распознается? Как я могу решить эту проблему

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;
    }
}
Теги:

1 ответ

2

здесь, изменить этот конструктор

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

и изменить это

@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;
            }
  • 0
    хотя этот ответ может сработать, можете ли вы объяснить свой ответ для ОП? это может помочь ему понять, что он сделал неправильно, и ваш ответ
  • 0
    что я должен передать при создании объекта класса Custom Adapter CustomAdapter a = new CustomAdapter (Description); дает ошибку.
Показать ещё 4 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню