开发者

can i use common adapter for different list view

My application is a bunch of ListViews (with a img, title, desc), for开发者_运维知识库 each Activity I am just subclassing the ListActivity and I am implementing corresponding custom Adapter that is on coding side, on layout side i'm defining a list layout, another layout for individual row for each screen.

After implementing 2-3 screens, I thought of reusing my exising layouts and Adapter.

Can anybody suggest the best way?


I don't know how your are doing the custom adapter but I guess it's an ArrayAdapter<Something>.

What you can do is creating an interface. Something like:

public interface Model {

 int getImage();
 String getTitle();
 String getDescription();

}

Make your classes implement that interface and use the interface inside the adapter to bind the data to the view.


Its possible to use common adapters depending on the data your are displaying .

Edit :

Basically one way to do it is build the data you want to display outside the adapter and then pass to the adapter . So your activities can build data as long as they are nearly similar and pass your adapter :-) . You can even pass flags to adapter which you can use in your adapter to conditionally hide data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜