我代码如下:
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版本的。
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版本的。
解决方案 »
- 使用Gson解析json报错了,哪位英雄看下。。
- android activity什么时间不进生命周期
- 动态填充TableLayout,如何让表格充满屏幕?如何设置动态生成的Textview的字体大小?
- 使用VideoView或者SurfaceView播放视频,视频没有显示在VideoView或者SurfaceView的中间,求如何让其居中显示,谢谢。
- Manifest.xml是在什么时候加载的
- [Android] Gallery里的video player能播放网络视频吗
- 高手请帮帮忙,帮看看是什么原因
- 小菜鸟求大神教教
- 如何进行数据类型转换?byte[] -> int
- AsyncTask到底能快多少?
- android开发中,使用Map API开发的软件生成apk文件时,不能安装,请问怎么解决啊?
- android没见过的异常
1、刷新project;
2、删掉R.java,重新生成一个;
3、重建project。。
对mInflater 赋值的时候你用这个试试
这种写法绝对没错。我的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;
}