mardi 27 novembre 2018

Checkbox data to firebase

How can I add checkbox values to my firebase database? Now I'm using edittext to store an item in the database. I want it to be checkable with a checkbox. And that it saves the checkboxes state even if I restart my app.

I've searched for an answer here, but no luck:( So I'm trying to ask for my self.

Model class:

public class Items {

String itemId;
String itemname;

public items(){


}

public Items (String itemId, String itemname){
    this.itemId = itemId;
    this.itemname = itemname;

}

public String getItemId() {
    return itemId;
}

public String getItemname() {
    return itemname;
}

Adapter:

public class listItems extends ArrayAdapter<Items> {

private Activity context;
private List<Items> listitems;



public listItems(Activity context, List<Items> listitems){
    super (context, R.layout.list_items, listitems);
    this.context = context;
    this.listitems = listitems;

}
@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();


    View listViewItem = inflater.inflate(R.layout.list_items, null, true);

    TextView tvitemname = (TextView) listViewItem.findViewById(R.id.tvitemname);
    CheckBox checkBox = (CheckBox) listViewItem.findViewById(R.id.checkbx);



    Items items = listitems.get(position);

    tvitemname.setText(items.getItemname());






    return listViewItem;
}




Aucun commentaire:

Enregistrer un commentaire