0
我目前從Firebase中提取數據並將其放入列表視圖中,並且所有工作正常。Firebase MultiSelect從ListView中刪除
該應用程序是一個決定輪,我需要讓用戶根據他們的個人偏好添加和刪除一些選擇。
他們將能夠在列表視圖中選擇多個項目,然後一次刪除所有項目。我還沒有找到任何方法可以做到這一點,這對我來說是完全沒有意義的。
public class RestaurantSelectionList extends Fragment {
DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mRestReference = mRootRef.child("restaurants");
List<String>listofrest = new ArrayList<String>();
ListView restaurantListView;
ListAdapter restaurantListAdapter;
public RestaurantSelectionList(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.restaurant_selection_list_frag,container,false);
restaurantListView = (ListView) view.findViewById(R.id.restaurantListView);
restaurantListAdapter = new FirebaseListAdapter<Restaurants>(getActivity(),Restaurants.class,R.layout.individual_restaurant_name,mRestReference) {
@Override
protected void populateView(View v, Restaurants model, int position) {
TextView restName = (TextView) v.findViewById(R.id.restname);
restName.setText(model.getName());
listofrest.add(position,model.getName());
}
};
restaurantListView.setAdapter(restaurantListAdapter);
restaurantListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
restaurantListView.setItemsCanFocus(false);
restaurantListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getActivity(), "clicked", Toast.LENGTH_SHORT).show();
}
});
return view;
}
}
這是我有我的列表視圖,我想知道這是否甚至可以用Firebase完成?這是我第一次與Firebase合作過,並且迄今爲止導致了很多問題。這是將顯示在列表: