我正在使用库SearchView提供的材料'com.miguelcatalan:materialsearchview:1.4.0'。该库使用setSuggestions将建议设置为搜索视图,如下面的代码所示。但是setSuggestions仅允许String[]。我想从Firebase加载项目列表,并放入建议中。问题是setSuggestion不允许ArrayList

materialSearchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
        @Override
        public void onSearchViewShown() {
            //Do some magic
            mProgress.setMessage("Loading...");
            mProgress.show();
            mDatabasePlaces.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {

                    for (DataSnapshot data:dataSnapshot.getChildren()){


                        Place models=data.getValue(Place.class);

                        placelist.add(models.getName());

                    }
                    mProgress.dismiss();
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });



            materialSearchView.setSuggestions(placelist);
        }

        @Override
        public void onSearchViewClosed() {
            //Do some magic
        }
    });



}


在代码场所列表中是ArrayList,而在materialSearchView.setSuggestions(placelist);中是不允许的。因此,我如何将该场所列表放入setSuggestions

最佳答案

您可以像这样将其解析为String[]

 String[] parsedArray = placelist.toArray(new String[placelist.size()])

10-08 13:42