Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向单个listview android添加多个适配器?_Android_Listview_Adapter - Fatal编程技术网

如何向单个listview android添加多个适配器?

如何向单个listview android添加多个适配器?,android,listview,adapter,Android,Listview,Adapter,我已经在单个视图中添加了2个适配器,以显示单个建议列表,并在获得不同列表的结果后。我不想在单个活动中创建2个列表视图。只需修改适配器 例如: wordsList.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item, R.id.listItem, matchedWordsList)); 我已经在处理程序中编写了这个步骤,给出了以下错误 只有创建视图层次结构的原始线程才能接触其 观点 我知道这个错误。但我的问题是---

我已经在单个视图中添加了2个适配器,以显示单个建议列表,并在获得不同列表的结果后。我不想在单个活动中创建2个列表视图。只需修改适配器

例如:

wordsList.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item, R.id.listItem, matchedWordsList));
我已经在处理程序中编写了这个步骤,给出了以下错误

只有创建视图层次结构的原始线程才能接触其 观点


我知道这个错误。但我的问题是---可以在单个listview中添加多个适配器吗?如果有,请给我关于这个的代码片段。

尝试在处理程序中使用下面的代码

runOnUiThread(new Runnable() {
     public void run() {

      wordsList.setAdapter(new CustomAdapter(this, mList));

    }
});

是的,您可以这样做,来自第一个适配器的内容将替换为来自第二个适配器的内容。您的错误与设置多个适配器无关

runOnUiThread(new Runnable() {
     public void run() {

      wordsList.setAdapter(new CustomAdapter(this, mList));

    }
});