Reputation: 35
Hello sorry for the massive code dump but I have can't quite figure out how to solve this.
For this application I'm making a listview filled with medical conditions and lifestyles affecting diet. So there is the condition listview and an ingredients listview under each conditions' title with a corresponding symbol meaning no or moderate.
I have gotten the condition listview to work fine but when i am calling the ingredients adapter an error shows up at the context parameter saying: Argument 1: cannot convert from 'FoodTranslate.TranslateAdapter' to 'Android.Content.Context' I was just wondering if there are changes to the second lot of code that can fix this. Thank you in advanced.
namespace FoodTranslate
{
class TranslateAdapter : BaseAdapter<OptionItem>
{
private List<OptionItem> Options;
private Context mContext;
public TranslateAdapter(Context context, List<OptionItem> items)
{
Options = items;
mContext = context;
}
public override int Count
{
get { return Options.Count; }
}
public override long GetItemId(int position)
{
return position;
}
public override OptionItem this[int position]
{
get { return Options[position]; }
}
//customising starts here
public override View GetView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if (row == null)
{
row = LayoutInflater.From(mContext).Inflate(Resource.Layout.ConditionItem, null, false);
}
TextView OptionName = row.FindViewById<TextView>(Resource.Id.OptionName);
ListView ingOut = row.FindViewById<ListView>(Resource.Id.Ingredients);
OptionName.Text = Options[position].Name;
//where the error occurs
IngredientAdapter ingAdapter = new IngredientAdapter(this, Options[position].Ingredients);
return row;
}
}
}
Ingredients listview:
namespace FoodTranslate
{
class IngredientAdapter : BaseAdapter<Ingredient>
{
private List<Ingredient> Ingredients;
private Context mContext;
public IngredientAdapter(Context context, List<Ingredient> items)
{
Ingredients = items;
mContext = context;
}
public override int Count
{
get { return Ingredients.Count; }
}
public override long GetItemId(int position)
{
return position;
}
public override Ingredient this[int position]
{
get { return Ingredients[position]; }
}
//Customising starts here
public override View GetView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if (row == null)
{
row = LayoutInflater.From(mContext).Inflate(Resource.Layout.IngredientItem, null, false);
}
TextView IngredientName = row.FindViewById<TextView>(Resource.Id.IngredientName);
ImageView imgLevel = row.FindViewById<ImageView>(Resource.Id.imgLevel);
IngredientName.Text = Ingredients[position].name;
switch (Ingredients[position].level)
{
case ("no"):
imgLevel.SetImageResource(Resource.Drawable.noldpi);
break;
case ("yes"):
imgLevel.SetImageResource(Resource.Drawable.yesldpi);
break;
case ("moderate"):
imgLevel.SetImageResource(Resource.Drawable.moderateldpi);
break;
};
return row;
}
}
}
Upvotes: 0
Views: 133
Reputation: 1566
Try passing mContext
instead of this
:-
IngredientAdapter ingAdapter = new IngredientAdapter(m, Options[position].Ingredients);
Upvotes: 1