Reputation: 83
I'm not sure what's wrong with this segment of code:
mylistview = (ListView) findViewById(R.id.list);
CustomAdapter adapter = new CustomAdapter(this, rowItems);
mylistview.setAdapter(adapter);
mylistview.setOnItemClickListener(this);
The line causing an error is mylistview.setAdapter(adapter). CustomAdapter is a java class with the constructor defined as so:
Context context;
List<RowItem> rowItems;
CustomAdapter(Context context, List<RowItem> rowItems){
this.context = context;
this.rowItems = rowItems;
}
The error I'm getting is: 'setAdapter(android.widget.ListAdapter)' in 'android.widget.ListView' cannot be applied to '(com.name.app.CustomAdapter)'
I have no idea what's causing this error and would greatly appreciate some insight as to why I can't set the adapter of my custom adapter to the listview. Thanks.
Upvotes: 0
Views: 800
Reputation: 164
Try this one
public class SpinnerAdapter extends BaseAdapter{
Context context;
ArrayList<String> list;
LayoutInflater layoutInflater;
SpinnerAdapter(Context context, ArrayList<String> list)
{
layoutInflater = LayoutInflater.from(context);
this.list = list;
this.context = context;
}
@Override
public int getCount()
{
return list.size();
}
@Override
public Object getItem(int position)
{
return list.get(position);
}
@Override
public long getItemId(int position)
{
return list.indexOf(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
convertView = layoutInflater.inflate(R.layout.spinner_s,null);
TextView client = (TextView) convertView.findViewById(R.id.client);
client.setText(list.get(position).toString());
return convertView;
}
Upvotes: 1
Reputation: 89
The setAdapter requires android.widget.ListAdapter. It looks like you CustomAdapter class needs to implement the ListAdapter interface
Upvotes: 0