如何将3个不同的arrayAdapter合二为一?

时间:2016-05-25 22:27:03

标签: android listview android-adapter

    List pdfFiles = new ArrayList();
    List directories = new ArrayList();
    List otherFiles = new ArrayList();

    /* Code to populate them */

    ArrayAdapter pdfFilesArrayAdapter = new ArrayAdapter(this, R.layout.pdf_files, pdfFiles);
    ArrayAdapter otherFilesArrayAdapter = new ArrayAdapter(this, R.layout.other_files, otherFiles);
    ArrayAdapter directoriesArrayAdapter = new ArrayAdapter(this, R.layout.directories, directories);

请注意,它们使用三种不同类型的TextView布局。 现在我有一个ListView ...

    ListView listView = (ListView) findViewById(R.id.list);

我想将所有适配器添加到此listView。如何将它们合并为一个?

1 个答案:

答案 0 :(得分:0)

如果您不想使用Library,则可以传递键值并在Adapter类中进行管理

ArrayAdapter pdfFilesArrayAdapter = new ArrayAdapter(this, R.layout.pdf_files, pdfFiles,"PDF"); ArrayAdapter otherFilesArrayAdapter = new ArrayAdapter(this, R.layout.other_files, otherFiles,"Other"); ArrayAdapter directoriesArrayAdapter = new ArrayAdapter(this, R.layout.directories, directories,"DIR");