我是android新手各位大神帮忙:
android程序 在View view = LayoutInflater.from(getContext()).inflate(resourceId, null); 这一句运行不下去额=了 是怎么回事
package com.example.listviewtest;
import java.util.List;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class FruitAdapter extends ArrayAdapter<Fruit> {
private int resourceId;
private String msg = "This is a logcat";
public FruitAdapter(Context context,int textViewResourceId,List<Fruit> objects){
super(context,textViewResourceId,objects);
resourceId = textViewResourceId;
Log.d("FruitAdapter", msg+"FruitAdapter()");
}
@Override
public View getView(int position,View convertView,ViewGroup parent){
Log.d("FruitAdapter", msg+"getView()"+"BEGIN");
Fruit fruit = getItem(position);
// View view =LayoutInflater.from(getContext()).inflate(resourceId, null);
Log.d("FruitAdapter", msg+"getView()"+"position1");
View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
Log.d("FruitAdapter", msg+"getView()"+"position2");
ImageView fruitImage = (ImageView)view.findViewById(R.id.fruit_image);
TextView fruitName = (TextView)view.findViewById(R.id.fruit_name);
fruitImage.setImageResource(fruit.getImageId());
fruitName.setText(fruit.getName());
Log.d("FruitAdapter", msg+"getView()"+"END");
return view;
}
}
最近刚刚学android 上面是一个FruitAdapter适配器类,为什么就在
View view = LayoutInflater.from(getContext()).inflate(resourceId, null); 这一句的位置上时就运行不下去了呀?上面我使用logcat打印信息来确认的
Log.d("FruitAdapter", msg+"getView()"+"position1");这句可以打印出来
但是Log.d("FruitAdapter", msg+"getView()"+"position2");这句变出不来了,这是为什么?(另:文中没有报错显示,在安卓机上效果是闪退。)