samedi 7 mai 2016

Android Checkbox, BYTE value to Int from ENUM

I am trying to get specific values from a checkbox dialog i have made with 4 options. So the four values represent bits, if the last option was checked and the rest unchecked it would result in 0001, if the first and last were selected it would give 1001.

I am having trouble actually getting the int value to represent BYTE value this is what i have so far

public enum Material
{
    FOLDABLE (1),
    OVERMAXKG (2),
    STORABLE (4),
    AVAILABLE (8);

    private byte val;


Material(int v)
{
    this.val = (byte) v;
}

public byte getValue()
{
    return val;
}

Material object class method for changing properties:

private byte materialProp;
public void adjustProperties(Matieral mat)
{
    materialProp = (byte) (materialProp ^ mat.getValue());
}

This is the alert dialog

AlertDialog matDialog;
    final CharSequence[] properties = {
             " Foldable ", " Exceeds 20KG ", " Storable ", " In Stock "};
    final ArrayList propList = new ArrayList();

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Select Material Properties");

How would i represent these values into BYTE format, that i can get the int value of?? So if i selected the checkboxes "Exceeds 20KG" then hit OK button it would represent 1001, which would then give me the BYTE value "0100"

Aucun commentaire:

Enregistrer un commentaire