Listview 覆盖列表视图的自定义适配器

Listview 覆盖列表视图的自定义适配器,listview,android-arrayadapter,overriding,Listview,Android Arrayadapter,Overriding,我是android开发新手 我正在尝试为我的listView创建arrayAdapter。我希望我的listView包含一个图像和两个文本视图。为此,我重写了ArrayAdapter的构造函数,也重写了getView方法。 我的应用程序每次尝试运行时都会停止。我在代码中找不到错误 public class main extends ActionBarActivity { String[] frnds; String[] depName; int[] images = {R.drawable.a

我是android开发新手
我正在尝试为我的listView创建arrayAdapter。我希望我的listView包含一个图像和两个文本视图。为此,我重写了ArrayAdapter的构造函数,也重写了getView方法。
我的应用程序每次尝试运行时都会停止。我在代码中找不到错误

public class main extends ActionBarActivity {

String[] frnds;
String[] depName;
int[] images = {R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e, R.drawable.f, R.drawable.g, R.drawable.h, R.drawable.i};
ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    lv = (ListView) findViewById(R.id.listView1);

    Resources res = getResources();

    frnds = res.getStringArray(R.array.names);
    depName = res.getStringArray(R.array.description);

    customAdapter adapter = new customAdapter(this, frnds, depName, images);
    lv.setAdapter(adapter);

}
}


class customAdapter extends ArrayAdapter<String> {

Context context;
String[] name;
String[] description;
int[] imgs;

customAdapter(Context c, String[] names, String[] desc, int img[]) {
    super(c, R.layout.single_row, R.id.textView1, names);
    this.context = c;
    this.imgs = img;
    this.name = names;
    this.description = desc;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View row = inflater.inflate(R.layout.single_row, parent, false);

    TextView tv1 = (TextView) row.findViewById(R.id.textView1);
    TextView tv2 = (TextView) row.findViewById(R.id.textView2);
    ImageView iv = (ImageView) row.findViewById(R.id.imageView1);

    tv1.setText(name[position]);
    tv2.setText(description[position]);
    iv.setImageResource(imgs[position]);

    return row;
}
}
public类main扩展了ActionBarActivity{
字符串[]frnds;
字符串[]depName;
int[]images={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e,R.drawable.f,R.drawable.g,R.drawable.h,R.drawable.i};
ListView lv;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView)findViewById(R.id.listView1);
Resources res=getResources();
frnds=res.getStringArray(R.array.names);
depName=res.getStringArray(R.array.description);
customAdapter=新的customAdapter(this、frnds、depName、images);
低压设置适配器(适配器);
}
}
类customAdapter扩展了ArrayAdapter{
语境;
字符串[]名称;
字符串[]说明;
int[]imgs;
customAdapter(上下文c,字符串[]名称,字符串[]描述,int-img[])){
super(c,R.layout.single_row,R.id.textView1,names);
this.context=c;
this.imgs=img;
this.name=名称;
this.description=desc;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
LayoutFlater充气器=(LayoutFlater)context.getSystemService(context.LAYOUT\u充气器\u服务);
视图行=充气机。充气(R.layout.single_row,parent,false);
TextView tv1=(TextView)row.findViewById(R.id.textView1);
TextView tv2=(TextView)row.findViewById(R.id.textView2);
ImageView iv=(ImageView)row.findViewById(R.id.imageView1);
tv1.setText(名称[职位]);
tv2.setText(描述[位置]);
iv.setImageResource(imgs[职位]);
返回行;
}
}

我面临的问题是因为内存问题
我尝试使用drawable文件夹中的图像,这会占用大量空间,并且因为显示了“内存不足”错误
此外,覆盖getView的代码也是无效的

我正在努力找到解决方案,并将努力让您不断更新