Reputation: 13456
I'm trying to make a ListView in Android with a dynamic field. First, I tried to set it up using static field which is shown below (String[] chars)
String[] chars = {"TEST"};
setListAdapter(new ArrayAdapter<String>(this,R.layout.resultlist,chars));
it gives me error The constructor ArrayAdapter<String>(ViewTranslationsList.GrabURL, int, int) is undefined
. Where's the problem?
I want to add items to the chars
array before I set up ArrayAdapter in for cycle.
Thanks
Upvotes: 0
Views: 2923
Reputation: 9
im not about your problem, but if you dont now about standard layout in android.
l.setListAdapter(new ArrayAdapter<String>(SomeActivity.this,android.R.layout.simple_list_item_1,chars));
or
l.setListAdapter(new ArrayAdapter<String>(SomeActivity.this,android.R.layout.simple_list_activated,chars));
or
l.setListAdapter(new ArrayAdapter<String> (SomeActivity.this,android.R.layout.simple_list_item_multiple_choice,chars));
l.setOnChoise(LISTVIEW.SET_MULTICHOISE_MODE);
read about standard layout. http://developer.android.com/reference/android/R.layout.html
Upvotes: 0
Reputation: 2776
here this
is ViewTranslationsList.GrabURL
ListView l = (ListView)findViewById(R.id.some)
l.setListAdapter(new ArrayAdapter<String>(SomeActivity.this,R.layout.resultlist,chars));
you have to pass Context
, ViewTranslationsList.GrabURL
is not Context
Upvotes: 0
Reputation: 46856
It looks like you are not inside your Activities context when you are calling your ArrayAdapter constructor. Try to change it like this:
setListAdapter(new ArrayAdapter<String>(yourActivityName.this,R.layout.resultlist,chars));
Though that may not be your only problem because based on the error it seems to think that chars is an int for some reason.
Upvotes: 1
Reputation: 23171
It looks like you're doing this inside an inner class (since the error is mentioning ViewTranslationsList.GrabURL
. If that is truly the case, try doing this:
setListAdapter(new ArrayAdapter<String>(ViewTranslationsList.this,R.layout.resultlist,chars));
Upvotes: 3