0

我正在使用 backendless,我正在尝试在列表视图中显示我的目录。我正在使用安卓工作室。

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Backendless.setUrl(Defaults.SERVER_URL);
        Backendless.initApp(this, Defaults.APPLICATION_ID, Defaults.SECRET_KEY, Defaults.VERSION);



        Backendless.Files.listing("/Uploads", "*docs", true, new AsyncCallback<BackendlessCollection<FileInfo>>() {
            @Override
            public void handleResponse(BackendlessCollection<FileInfo> fileInfoBackendlessCollection) {
                Iterator<FileInfo> filesIterator = fileInfoBackendlessCollection.getCurrentPage().iterator();
                while (filesIterator.hasNext()) {
                    FileInfo file = filesIterator.next();
                    String URL = file.getURL();
                    String publicURL = file.getPublicUrl();
                    Date createdOn = new Date(file.getCreatedOn());
                    String name = file.getName();

                    String[] info = {URL, publicURL, name};
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView().getContext(), android.R.layout.simple_list_item_1, info);
                    getListView().setAdapter(adapter);

                }
            }

            @Override
            public void handleFault(BackendlessFault backendlessFault) {

            }
        });

    }
}

它没有错误,但应用程序无法打开。谁能帮我做什么?

4

1 回答 1

0

这是解决问题的开始:

        @Override
        public void handleResponse(BackendlessCollection<FileInfo> fileInfoBackendlessCollection) {

            // create a list for your data
            List<String> infoList = new ArrayList<>();

            Iterator<FileInfo> filesIterator = fileInfoBackendlessCollection.getCurrentPage().iterator();
            while (filesIterator.hasNext()) {
                FileInfo file = filesIterator.next();
                String URL = file.getURL();
                String publicURL = file.getPublicUrl();
                Date createdOn = new Date(file.getCreatedOn());
                String name = file.getName();

                // put everything into one string temporarily
                // String[] info = {URL, publicURL, name};
                String info = URL + " " + publicURL + " " + name;
                infoList.add(info);
            }

            // loop through ALL your data before creating/assigning adapter
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView().getContext(), android.R.layout.simple_list_item_1, infoList);
            getListView().setAdapter(adapter);
        }

现在你的适配器会变得更复杂一些,因为你不想把所有东西都放在一条线上。您需要为列表项创建布局。然后您需要使用SimpleAdapter或创建一个自定义类扩展BaseAdapter并使用它来显示您的数据。

于 2016-02-21T20:13:10.533 回答