Reputation: 841
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<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getPackages());
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;
}
Upvotes: 1
Views: 11717
Reputation: 6598
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());
into this:
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(YourActivity.this, android.R.layout.simple_list_item_1, getPackages());
The main difference is first parameter - YourActivity.this
which is reference to your activity in which you are setting your adapter.
Upvotes: 2
Reputation: 13247
Obviously you are creating your adapter in a Runnable
(in run()
method), that's why this
refers to the Runnable
, not to a Context
. Try to use YourActivity.this
instead of this
.
Upvotes: 0