0

我正在使用适配器构建字符串列表,如何根据特定条件将不同的布局属性应用于这些项目?

例如,假设您需要检查列表项的文本是否包含特定单词,然后根据测试结果,您想要增加或减少其边距(如果这有任何意义: D)。

4

2 回答 2

0

您可以使用ContextThemeWrapper根据您的特定条件提供不同的主题。

于 2012-05-08T15:06:05.247 回答
0

创建一个如下所示的适配器。这里只更改了背景颜色,请尝试根据您的情况更改那里的布局....

    public class SpecialAdapter extends SimpleAdapter {
    private int[] colors = new int[] { 0x30FF0000, 0x300000FF };

    public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
        super(context, items, resource, from, to);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = super.getView(position, convertView, parent);
      int colorPos = position % colors.length;
      view.setBackgroundColor(colors[colorPos]);
      return view;
    }
}

有关更多详细信息,请查看此链接http://eureka.ykyuen.info/2010/03/15/android-%E2%80%93-applying-alternate-row-color-in-listview-with-simpleadapter/

于 2012-05-08T15:43:10.667 回答