vendredi 29 janvier 2016

Updating Android List Elements with Seeker Bar

I am trying to implement a seeker bar that will update elements in my listview. At the moment list is populated by a cursor that retrieves all the rows (name and a value) from my SQLite database.

So for example when the seekbar is moved to say 3 all the values in the list will be multiplied by 3. I only want this to change in the listview and not update the rows in the database.

At the moment I have the seekbar working but I cant figure out how to change the values of the cursor in the listview. Or is what I am trying to do even possible?

Cursor

    final Cursor rows = adapter.getRows();
    String[] columns = new String[] {adapter.KEY_NAME, adapter.KEY_VALUE};
    int[] to = new int[] {R.id.Name, R.id.Value};
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.row, rows, columns, to, 0);
    ListView entriesList = (ListView) findViewById(R.id.entries);
    entriesList.setAdapter(adapter);

SeekBar

    seekBar = (SeekBar) findViewById(R.id.SeekBar1);
    textView = (TextView) findViewById(R.id.Textview1);
    // Initialize the textview with '0'
    textView.setText("Seek Size:" + seekBar.getProgress());
    seekBar.setOnSeekBarChangeListener(
            new SeekBar.OnSeekBarChangeListener() {
                int progress = 0;

                @Override
                public void onProgressChanged(SeekBar seekBar,
                                              int progresValue, boolean fromUser) {
                    progress = progresValue;
                    textView.setText("Serving Size:" + progress);
                    //This is were I think I need to update the values of the cursor

                    //update cursor

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {

                }
            });

Aucun commentaire:

Enregistrer un commentaire