ArrayList转换为ArrayAdapter

ArrayList转换为ArrayAdapter

本文介绍了ArrayList转换为ArrayAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将arraylist方法放入arrayadapter中,但我无法这样做.我正在未定义构造函数ArrayAdapter< String>(new Runnable(){},int,ArrayList< RetrieveInternet>)

I'm trying to put an arraylist method into an arrayadapter but i am unable to do so.I am getting The constructor ArrayAdapter<String>(new Runnable(){}, int, ArrayList<RetrieveInternet>) is undefined

ArrayAdapter

ArrayAdapter

            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getPackages());

Arraylist方法:

Arraylist method:

private ArrayList<RetrieveInternet> getPackages() {
    ArrayList<RetrieveInternet> apps = getPermissions(true); /* false = no system packages */
    final int max = apps.size();
    for (int i=0; i<max; i++) {
        apps.get(i);
        Log.e("TAG", apps.get(i).toString());
    }
    return apps;
}

推荐答案

ArrayAdapter 构造函数的第一个参数应为 Context 而不是 Runnable .您可能是在某些 Runnable 中设置适配器的,所以您不能使用 this 引用,因为它指向该 Runnable 实例.您应该更改此行:

First parameter of ArrayAdapter constructor should be Context not Runnable. You are probably setting your adapter from within some Runnable so you cannot use this reference because it pointing at that Runnable instance. You should change this line:

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getPackages());

对此:

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(YourActivity.this, android.R.layout.simple_list_item_1, getPackages());

主要区别是第一个参数- YourActivity.this ,它是您在其中设置适配器的活动的引用.

The main difference is first parameter - YourActivity.this which is reference to your activity in which you are setting your adapter.

这篇关于ArrayList转换为ArrayAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:15