如何从sqlite数据库字段中设置seekbar最大值

时间:2019-01-30 20:02:56

标签: android android-sqlite android-spinner android-seekbar

首先,这是一个问题,但是几个小时后,我为此编写了代码。 我想通过“整数”列中的字段设置seekbar的最大值,微调框使用该表中的其他“字符串”列,我不得不在它们之间进行关联。 db.java中有一个类:

 public Cursor showValue(){
    SQLiteDatabase db = this.getWritableDatabase();
    return db.rawQuery("select " + COL_4 + " from " +TABLE_NAME, null);
}

有活动:

public class zones extends AppCompatActivity {
private static SeekBar seekAdult;
private static SeekBar seekKid;
private static TextView txtAdultNumber;
private static TextView txtKidNumber;
private Integer volx;
private Integer voly;
Spinner spinner;
DataBaseHelper myDb;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_zones);
    myDb = new DataBaseHelper(this);
    spinner = (Spinner) findViewById(R.id.spinner);
    txtAdultNumber = (TextView) findViewById(R.id.txtAdultNumber);
    txtKidNumber = (TextView) findViewById(R.id.txtKidNumber);
    spinnerdata();

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            int x = parent.getSelectedItemPosition();
            final Cursor c = myDb.showValue();
            if (c.getCount() == 0){
                volx = 0;
                voly = 0;
            }
            else c.moveToPosition(x);
            volx = c.getInt(0);
            voly = c.getInt(0);
            c.close();
            seekbaradult(volx);
            seekbarkid(voly);
        }

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

public void spinnerdata () {
    DataBaseHelper db = new DataBaseHelper(getApplicationContext());
    List<String> listname = db.showZonesList();
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_item, listname);
    spinner.setAdapter(dataAdapter);

}

public void seekbaradult (Integer y) {
    seekAdult = (SeekBar)findViewById(R.id.seekAdult);
    txtAdultNumber.setText(""+seekAdult.getProgress() );
    //values in this column are multiplications of "30"
    int max = y / 30;
    seekAdult.setMax(max);
    seekAdult.setOnSeekBarChangeListener(
            new SeekBar.OnSeekBarChangeListener() {
                int progress_value;
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    progress_value = progress;
                    txtAdultNumber.setText("" +progress);
                }
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    txtAdultNumber.setText(""+progress_value);
                }
            }
    );
}

public void seekbarkid (Integer y) {
    seekKid = (SeekBar)findViewById(R.id.seekKid);
    txtKidNumber.setText(""+seekKid.getProgress() );
    int max2 = y / 30;
    seekKid.setMax(max2);
    seekKid.setOnSeekBarChangeListener(
            new SeekBar.OnSeekBarChangeListener() {
                int progress_value;

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    progress_value = progress;
                    txtKidNumber.setText("" +progress);

                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    txtKidNumber.setText(""+progress_value);

                }
            }
    );
}

}

但是,现在,如何为这两个导杆设置一个最大值?

0 个答案:

没有答案