I'm trying to create a custom adapter for my Categories list. For some reason I can't access my category_item layout when I'm trying to inflate it. Here's my code:
public class CategoryAdapter extends ArrayAdapter<Category> {
LayoutInflater mInflater;
List<Category> list;
public CategoryAdapter(Context context, int resource, int textViewResourceId, List<Category> objects) {
super(context, resource, textViewResourceId, objects);
mInflater = LayoutInflater.from(context);
list = objects;
}
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null){
convertView=mInflater.inflate(***resource***, null);
holder = new ViewHolder();
}
return convertView;
}
// Declaring new class ViewHolder
class ViewHolder{
TextView category_name;
}
Where it says resource
I should be able to access to my category_item.xml layout - R.layout.category_item. But for some reason I don't see it in the list, I can't access it. In the matter of fact I don't see any of my layouts in the list.
Why is it happening and how can it be fixed?
Import your packagename.R
file and it will work. It may be possiblity that you imported android.R
. As you resource exists in you application package, just correct it and it will work.
android.R refers to sdk resources.
It is possible that you imported android resources package android.R
Make sure you imported your package resources com.yourpackagename.R
. This should fix your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With