【问题标题】:Using same custom array adapter for listview and grid view对列表视图和网格视图使用相同的自定义数组适配器
【发布时间】:2013-04-26 17:09:05
【问题描述】:

我有一个仪表板,以网格视图和列表视图两种视图显示文件。 我为两者使用了两个单独的自定义数组适配器对象。有什么方法可以为两个视图使用相同的数组适配器

ArrayList<DocumentItem> documentsList = new ArrayList<DocumentItem>();

目前网格视图适配器看起来像

DocumentsListAdapter gridAdapter = new DocumentsListAdapter(this, R.layout.grid_documentitem, documentsList); 

列表视图看起来像

DocumentsListAdapter listAdapter = new DocumentsListAdapter(this, R.layout.list_documentitem, documentsList);

两者都因用于显示项目的布局而异。请指导我克服这种重复

【问题讨论】:

    标签: android performance android-widget


    【解决方案1】:

    是的,您必须使用通用类并为列表视图和网格视图使用单独的对象才能访问它。

    【讨论】:

    • 你是说我在做什么是正确的吗?但是当我向一个视图添加一个新项目时,我必须复制代码以将其反映在另一个视图中。有没有办法做到这一点。
    猜你喜欢
    • 2014-05-02
    • 2011-12-31
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多