How to update a Spinner from Edittext data on Android

Asked

Viewed 109 times

0

I have a Spinner that is being filled with Sqlite data, I want to take this data, edit them and update them

My Spinnerdatabase class method (responsible for the Spinner database)

public void alteraRegistroSpinner (int id, String label){
        ContentValues values;
        String where;

        db = this.getWritableDatabase();

        where = SpinnerDatabase.KEY_ID + "=" +id;

        values = new ContentValues();
        values.put(SpinnerDatabase.KEY_NAME,label);

        db.update(SpinnerDatabase.TABLE_LABELS,values,where,null);
        db.close();
    }

Method in my Fragment playing Spinner dice in Edittext

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                String passaValor = spinner.getItemAtPosition(position).toString();
                editarAssunto.setText(passaValor);

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

I need to call inside the onItemSelectedListener? How do I pass the new data to the BD?

  • What list or array is with the database values ?

  • Essa aqui: private void loadSpinnerData (){&#xA; SpinnerDatabase db = new SpinnerDatabase(getActivity().getApplicationContext());&#xA;&#xA; List<String> labels = db.getAllLabels();&#xA;&#xA; ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_spinner_item,Labels); Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(Adapter); }

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.