samedi 10 décembre 2016

Check to see if CheckBox is clicked and if it is then set to String - Firebase

I have a list of Restaurants that have checkboxes next to them and I am pulling this information from Firebase.

public class RestaurantSelectionList extends Fragment {

DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mRestReference = mRootRef.child("restaurants");

List<String>listofrest = new ArrayList<String>();
ListView restaurantListView;
FirebaseListAdapter restaurantListAdapter;
Button readytogoBtn;
TextView option1;
TextView option2;
TextView option3;
TextView option4;
TextView option5;
TextView option6;




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);
    readytogoBtn = (Button) view.findViewById(R.id.readytospinbtn);

    restaurantListAdapter = new FirebaseListAdapter<Restaurants>(getActivity(),Restaurants.class,R.layout.individual_restaurant_name_checkbox,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);
    return view;
}
}

This is the code I have so far. My question is, how can I get the string of the items that are checked when a button is clicked. Also the user can not check more than 6 items from the list and they have to choose at least 2. Then the name of the restaurant needs to be retrieved for each item checked and call toString(). These strings will then be set to the Textviews that are above.




Aucun commentaire:

Enregistrer un commentaire