android将多个适配器连接到一个适配器 [英] android attaching multiple adapters to one adapter

查看:47
本文介绍了android将多个适配器连接到一个适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 分离列表适配器 非常有名并且工作完美,但似乎我不能使用 addSection() 添加一个 SimpleAdapter,因为应用程序已终止.我提供了一些代码来向您展示我正在尝试做什么并获得一些指导以解决此问题.如果您需要任何其他代码或任何内容,请告诉我:

I have been using the SeparatedListAdapter which is very well known and works perfectly, but it seems that I cannot use the addSection() to add a SimpleAdapter, because the application is terminated. I'm providing some code to show you what I'm trying to do and get some guidance in order solve this issue. Please let me know if you need any other piece of code or anything:

// Declarations

private SimpleAdapter _resultsAdapter;
private ArrayAdapter<String> _adapter;
private List<Map<String,?>> _resultsList;
private ArrayList<String> _stringList = new ArrayList<String>();

// Much of source code here

// The following lines work (I can addSection()).
    _adapter =  new ArrayAdapter<String>(this, R.layout.custom_list_item, _stringList);
    _sla = new SeparatedListAdapter(this);
    _sla.addSection("Input Data", _adapter);  

// More source code here...

// The following causes a crash
_resultsList.add(createItem(resultTitle.toString(), fieldDetails.toString())); // Loading data in a loop (works 100%)
_resultsAdapter = new SimpleAdapter(CompanyInfoServiceViewActivity.this, _resultsList, R.layout.list_complex, new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption });
_sla.addSection("Results", _resultsAdapter); // Crashes here. _sla is not null (see above)

推荐答案

添加了这一行:

setListAdapter(_sla);

线下:

_sla.addSection("Results", _resultsAdapter);

这篇关于android将多个适配器连接到一个适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆