Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android generic ArrayAdapter

I have multiple classes, which all extend some BasicDataModel:

public class NewsItem extends BasicDataModel
public class PhotosItem extends BasicDataModel

etc. So I need to make ArrayAdapters for all of them, and I wonder if it is possible to make some generic ArrayAdapter to fit all my objects. So far I tried to make

public class MyAdapter extends ArrayAdapter<BasicDataModel> 

but as long as I pass ArrayList, for example, this doesn't work.

Thanks in advance

like image 981
Roman Avatar asked Sep 01 '26 06:09

Roman


2 Answers

Try

public class MyAdapter<T extends BasicDataModel> extends ArrayAdapter<T>

and use

MyAdapter<NewsItem> news;
like image 175
Mikita Belahlazau Avatar answered Sep 02 '26 19:09

Mikita Belahlazau


I tried Nikita Beloglazov suggestion:

public class MyAdapter<T> extends ArrayAdapter<T extends BasicDataModel>

but found that it wouldn't compile.

Then I tried:

public class MyAdapter<T extends BasicDataModel> extends ArrayAdapter<T>

and that worked just fine :)

like image 33
ProjectDelta Avatar answered Sep 02 '26 20:09

ProjectDelta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!