我想在我的应用程序中使用列表视图,我进行了正确的编码,但是当我运行该应用程序时它会关闭。这是我的代码:
setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,R.id.textView1,getResources().getStringArray(R.array.cities)));
}
适配器
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] string) {
super(context, resource, textViewResourceId, string);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater in=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=in.inflate(R.layout.list_item, parent, false);
String[] items=getResources().getStringArray(R.array.cities);
TextView tv=(TextView) row.findViewById(R.id.textView1);
return super.getView(position, convertView, parent);
}
}
}