创建自己的适配器时遇到问题
因此,我将观看 lynda.com 上有关创建自定义列表布局的视频。我已经观看了视频,但我无法更改构造函数来更改代码,因此它是一个字符串数组。在我编写 MyAdapter 的两个地方,下面都有红色波形曲线,顶部波形曲线告诉我 MyAdapter 无法解析为类型。请帮忙。
setListAdapter(new MyAdapter<String>(CustomList2Activity.this,
android.R.layout.simple_list_item_1, R.id.textView1, getResources().getStringArray(R.array.companies2)));
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource,
int textViewResourceId, List<String> objects) {
super(context, resource, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
So I'm going along with a lynda.com video on creating a custom list layout. I have gone along with the video but I am not able to change my constructor in order to change the code so it is an array of strings. In both places where I have written MyAdapter, there is a red squiggle below and the top one tells me MyAdapter cannot be resolved to a type. Please assist.
setListAdapter(new MyAdapter<String>(CustomList2Activity.this,
android.R.layout.simple_list_item_1, R.id.textView1, getResources().getStringArray(R.array.companies2)));
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource,
int textViewResourceId, List<String> objects) {
super(context, resource, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您在正确的位置声明 MyAdapter 类。确保您没有在函数中声明它。另外,转到源菜单(假设您使用的是 eclipse)并按“组织导入”以确保导入正确。
Make sure you are declaring the MyAdapter class in the right place. Make sure you're not declaring it within a function. Also, go to the source menu (assuming you're using eclipse) and press "organize imports" to make sure your imports are right.