Iga*_*gal 4 android android-arrayadapter android-layout layout-inflater custom-adapter
我正在尝试为我的类别列表创建自定义适配器.出于某种原因,当我试图给它充气时,我无法访问我的category_item布局.这是我的代码:
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;
}
它说resource我应该能够访问我的category_item.xml布局 -  R.layout.category_item.但由于某些原因我没有在列表中看到它,我无法访问它.事实上,我在列表中看不到任何布局.
为什么会发生这种情况?如何解决?
Akb*_*ali 13
导入您的packagename.R文件,它将工作.您可能有可能导入android.R.由于您的应用程序包中存在资源,只需更正它并且它将起作用.
android.R指的是sdk资源.
| 归档时间: | 
 | 
| 查看次数: | 5339 次 | 
| 最近记录: |