I know that ListAdapter is an interface and ArrayAdapter is a class. So we can only instantiate ArrayAdapter. I met up a code
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songNames);
But I was able to do the same thing with
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songsArray);
So I want to know, in what exact places do we need ListAdapter ?
Thank you
This is not related to Android. But a general Java question.
When you use ListAdapter
as the type for your variable, you are really interested in the interface. You may not be interested in calling some specific method of ArrayAdapter<String>
not available in ListAdapter
. That is mainly because you will just assign the adapter as the list adapter for the view.
You may use the precise type of ArrayAdapter<String>
if you really need to call some specific methods.
It all depends on your use case.