RoyceNguyen / BuildCalculator

0 stars 0 forks source link

Getting selected value of Spinner when clicking submit #14

Open Blazeblackbird opened 7 years ago

Blazeblackbird commented 7 years ago

@cfiliault Hey Cai, how do I grab my item that is selected in Spinner when user clicks submit button? I have;

DatabaseHandler db = new DatabaseHandler(getContext());

    //Use ArrayList on Item to get all the weapons and gears seperately to populate Spinners
    ArrayList<Item> weaponList = db.getAllWeapons();
    ArrayList<Item> gearList = db.getAllGears();
    db.closeDB();
    //Adding Spinner code to grab the correct items to display
    //Create an ArrayAdapter to grab context and use weaponList and gearList
    ArrayAdapter adapter1 = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, weaponList);
    ArrayAdapter adapter2 = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, gearList);
    //Apply the adapter to the spinner
    weapon.setAdapter(adapter1);
    gear.setAdapter(adapter2);

Then in submit button I have;

            Build build = new Build(name.getText().toString(), weapon.getSelectedItemId(), gear.getSelectedItemId());

Errors in above line are with weapon.getSelectedItemId() and gear.getSelectedItemId()

Blazeblackbird commented 7 years ago

@cfiliault I changed my int gear and int weapon to long's in my Build class. It shows no errors and the app runs, but when I click on "builds" in the nav drawer the app crashes and doesn't show any errors in the event log.

Blazeblackbird commented 7 years ago

@cfiliault

After fixing about 3 Database errors I'm stuck on this one now;

                                                                           android.database.sqlite.SQLiteException: table gear has no column named ARMOR (code 1): , while compiling: INSERT INTO gear(NAME, HEALTH, ARMOR, MAGICRESIST ) VALUES ('MYSTICAL MAIL', 1300, 400, 350)
cfiliault commented 7 years ago

@Blazeblackbird I did a quick glance at your DatabaseHandler and saw the following: private static final String COLUMN_ARMOR = "aromr"; and when I look at your insert query I see the following: db.execSQL("INSERT INTO " + TABLE_GEAR + "(NAME, HEALTH, ARMOR, MAGICRESIST ) VALUES ('MYSTICAL MAIL', 1300, 400, 350)"); I think you will find you are having issues because you did not reuse your column constants and ended up with a typo. You have the following error: android.database.sqlite.SQLiteException: table gear has no column named ARMOR (code 1): , while compiling: INSERT INTO gear(NAME, HEALTH, ARMOR, MAGICRESIST ) VALUES ('MYSTICAL MAIL', 1300, 400, 350) This is correct because your column is named 'aromr' not 'ARMOR'

To remedy this change private static final String COLUMN_ARMOR = "aromr"; To: private static final String COLUMN_ARMOR = "ARMOR";

finally you will need to uninstall and reinstall the app for the changed to take effect.

Blazeblackbird commented 7 years ago

@cfiliault @RoyceNguyen Ok I got it working thus far. Now the issue I have is with our Spinners, first thing when I click on a spinner to see all the items inside it shows as a string of text like this; screenshot_1492624034

Secondly, when the user hits submit and enters the build.. how do we grab the exact build for the Damage Calculator to use it?