当前位置:编程学习 > wap >>

inflate() android sdk中调用该方法调试时报Source not found问题

我代码如下:
private LayoutInflater mInflater = null;
public MyAdapter(Context context,int[] _color,int[] _text)
{
    mInflater = LayoutInflater.from(context);
    color = _color;
    text = _text;
}
public View getView(int position, View convertView, ViewGroup parent) {
      //View test_view = null;
     if(convertView == null)
     {
       convertView = mInflater.inflate(R.layout.changecolor, null);//调试时就在这句报找不资源了。
       //test_view = View.inflate(context, R.layout.changecolor, null);这个是我在网上找的还以为1.5版本的是用它//可以代替上面那inflate方法可用了还是不行报一样的错误。
       veiw_Holder = new ViewHolder();
veiw_Holder.m_Text = (TextView)convertView.findViewById(R.id.my_text);
emp_view.setTag(veiw_Holder);
     }else
          veiw_Holder = (ViewHolder)convertView.getTag();
veiw_Holder.m_Text.setText(text[position]);
veiw_Holder.m_Text.setBackgroundResource(color[position]);
return convertView;
}
哪个如果知道的话就告诉我下。我用的是sdk 1.5 r2版本的。 --------------------编程问答-------------------- 我后来看了下我那res/layout/changecolor.xml有这文件,可为什么还说找不到哦? --------------------编程问答-------------------- convertView = mInflater.inflate(R.layout.changecolor, null);//调试时就在这句报找不资源了。 

convertView = context.mInflater.inflate(R.layout.changecolor, null);

context是你构造时传进来的 --------------------编程问答-------------------- 恩,是的 --------------------编程问答-------------------- Android的project里面经常会碰到这种错误,你可以试试:
1、刷新project;
2、删掉R.java,重新生成一个;
3、重建project。。 --------------------编程问答-------------------- 我试了还是没什么用。 --------------------编程问答-------------------- mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


对mInflater 赋值的时候你用这个试试 --------------------编程问答-------------------- 这个应该没用

LayoutInflater.from(context); 方法最后也是调用的(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  --------------------编程问答-------------------- --------------------编程问答-------------------- 学习中.... --------------------编程问答-------------------- convertView = mInflater.inflate(R.layout.changecolor, null);
这种写法绝对没错。我的android版本和你一样,没有问题。
还是从资源上入手吧 --------------------编程问答-------------------- 建议检查下全部资源,看是否其他资源有错,如果其他资源有错,也会出现新添加的正确资源找不到的情况。 --------------------编程问答-------------------- 首先声明:我不是为分而来的,我是为学技术而解答的!
不知道你的问题解决了没有,我这里有一种解决方案,你可以参考一下:
我将修改的地方用红色标记出来,你再试试看!

private LayoutInflater mInflater = null; 
public MyAdapter(Context context,int[] _color,int[] _text) 

    mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);    color = _color; 
    text = _text; 

public View getView(int position, View convertView, ViewGroup parent) { 
    if(convertView == null) 
    { 
      convertView = (View)mInflater.inflate(R.layout.changecolor, null);//调试时就在这句报找不资源了。 
      veiw_Holder = new ViewHolder(); 
      veiw_Holder.m_Text = (TextView)convertView.findViewById(R.id.my_text); 
      emp_view.setTag(veiw_Holder); 
    }else 
          veiw_Holder = (ViewHolder)convertView.getTag(); 
    veiw_Holder.m_Text.setText(text[position]); 
    veiw_Holder.m_Text.setBackgroundResource(color[position]); 
    return convertView; 
}  --------------------编程问答-------------------- 我也遇到了同样的错误
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,