如何提升适配器在Android中使用addItem功能?

如何提升适配器在Android中使用addItem功能?,android,adapter,android-arrayadapter,Android,Adapter,Android Arrayadapter,我有个问题。我不能修改一些代码来提升它的功能 代码如下: final Item[] items = { new Item("Email", android.R.drawable.ic_menu_add, 7), new Item("Facebook", resId, 99), }; ListAdapter adapter = new ArrayAdapter<Item>(

我有个问题。我不能修改一些代码来提升它的功能

代码如下:

final Item[] items = {
                new Item("Email", android.R.drawable.ic_menu_add, 7),
                new Item("Facebook", resId, 99),
            };

            ListAdapter adapter = new ArrayAdapter<Item>(
                this,
                android.R.layout.select_dialog_item,
                android.R.id.text1,
                items){
                    public View getView(int position, View convertView, ViewGroup parent) {
                        //User super class to create the View
                        View v = super.getView(position, convertView, parent);
                        TextView tv = (TextView)v.findViewById(android.R.id.text1);

                        //Put the image on the TextView
                        tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);

                        //Add margin between image and text (support various screen densities)
                        int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
                        tv.setCompoundDrawablePadding(dp5);

                        return v;
                    }
                };
我想修改这个类项目以方便添加项目,例如,
Item.addItem(str,int,int)

如何做到这一点?

List items=new ArrayList();
List<Item> items = new ArrayList<Item>();

items.add(new Item(str,int,int));
添加(新项目(str,int,int));
使用ArrayList而不是arrayPlease,你能解释一下怎么做吗?我需要替换此代码:
final Item[]items={新项(“Email”,android.R.drawable.ic_menu_add,7),新项(“Facebook”,resId,99),};如下所示:
Item items=new Item();对于(int i;如果我收到错误,我的答案看起来不错:
类型不匹配:无法从ArrayList转换为List
。我只想创建类项目的副本,并在循环中添加项目。谢谢!请先编写字符串而不是项目,在复制和粘贴代码之前请考虑。现在答案中已修复。在我在第一篇文章中编写的代码中,给我一个错误:
tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon,0,0);
错误:
表达式的类型必须是数组类型,但它已解析为列出
tv.setCompoundDrawablesWithIntrinsicBounds(items.get(position).icon,0,0)
但是你似乎会陷入程序的每一个步骤,你应该从一个教程开始(对于纯java)。哦,伙计,你节省了我的时间,你是对的,我需要一个教程,因为我不是java开发者,而我只是在java中尝试。非常感谢你!你帮我解决了我两天的任务!我很高兴)
List<Item> items = new ArrayList<Item>();

items.add(new Item(str,int,int));