Reputation: 87
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;
}
}
Upvotes: 0
Views: 55
Reputation: 1500
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;
}
Upvotes: 2