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

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

问题描述

我一直使用 SeparatedListAdapter 这是众所周知的和完美的作品,但似乎我不能使用Addsection的()来添加SimpleAdapter,因为应用程序被终止。我提供了一些code来告诉你什么是我想要做的,并得到以一定的指导解决这个问题。请让我知道,如果你需要的任何其他部分的code或东西:

  //声明

私人SimpleAdapter _resultsAdapter;
私人ArrayAdapter<字符串> _适配器;
私人名单,其中,地图<字符串,>> _resultsList;
私人的ArrayList<字符串> _stringList =新的ArrayList<字符串>();

//大部分源$ C ​​$ C在这里

//以下行的工作(我可以Addsection的())。
    _adapter =新的ArrayAdapter<字符串>(这一点,R.layout.custom_list_item,_stringList);
    _sla =新SeparatedListAdapter(本);
    _sla.addSection(输入数据,_adapter);

//更多源$ C ​​$ C在这里...

//下导致系统崩溃
_resultsList.add(createItem中(resultTitle.toString(),fieldDetails.toString())); //在循环中加载数据(作品100%)
_resultsAdapter =新SimpleAdapter(CompanyInfoServiceViewActivity.this,_resultsList,R.layout.list_complex,新的String [] {ITEM_TITLE,ITEM_CAPTION},新的INT [] {R.id.list_complex_title,R.id.list_complex_caption});
_sla.addSection(结果,_resultsAdapter); //崩溃这里。 _sla不为空(见上文)
 

解决方案

补充该行:

  setListAdapter(_sla);
 

下面的一行:

  _sla.addSection(结果,_resultsAdapter);
 

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)

解决方案

Added this line:

setListAdapter(_sla);

below the line:

_sla.addSection("Results", _resultsAdapter);

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

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