将搜索栏值保存到数据库

saving seekbar value to the database

我遇到了一个问题。我想将 seekbar 的值发布到数据库中。我怎样才能在此处使用该值:

这段代码又在底部:

 public void poslji (View view){

        String poslji_data = test.getText().toString().trim();
        String type ="Poslji";
        BackgroundWorker backgroundWorker = new BackgroundWorker(this);
        backgroundWorker.execute(type, poslji_data);
        }
}

这是完整的代码:

public class MainActivity extends ActionBarActivity {

   // private TextView test;
    private TextView textView;
    private ImageView imageView;
    private SeekBar seekBar;
    private TextView strI;

    EditText test;


    @Override
     protected void onCreate(Bundle savedInstanceState) {
       super.onCreate( savedInstanceState );
       setContentView( R.layout.activity_main );

       seekBar = (SeekBar) findViewById( seek_bar_id );

        test = (EditText)findViewById(R.id.test_id);

       initializeVariables();

       textView.setText( "Jakost bolečine: " + seekBar.getProgress() + "/" + seekBar.getMax() );

       seekBar.setOnSeekBarChangeListener( new OnSeekBarChangeListener() {
           int progress = 0;

           @Override
           public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
               progress = progresValue;
           }

           @Override
           public void onStartTrackingTouch(SeekBar seekBar) {
           }

           @Override
           public void onStopTrackingTouch(final SeekBar seekBar) {

               textView.setText( "Jakost bolečine: " + progress + "/" + seekBar.getMax() );
               if (progress == 0) {

                   imageView.setImageResource( R.drawable.no_pain );
               }
               if (progress <= 2 && progress >= 1) {
                   imageView.setImageResource( R.drawable.little_pain );
                   Toast.makeText( getApplicationContext(), "Blaga bolečina!", Toast.LENGTH_SHORT ).show();
               }

               if (progress <= 4 && progress >= 3) {
                   imageView.setImageResource( R.drawable.moderata_pain );
                   Toast.makeText( getApplicationContext(), "Zmerna bolečina!", Toast.LENGTH_SHORT ).show();
               }

               if (progress <= 6 && progress >= 5) {
                   imageView.setImageResource( R.drawable.severe_pain );
                   Toast.makeText( getApplicationContext(), "Srednja bolečina!", Toast.LENGTH_SHORT ).show();
               }

               if (progress <= 8 && progress >= 7) {
                   imageView.setImageResource( R.drawable.very_severe_pain );
                   Toast.makeText( getApplicationContext(), "Dokaj močna bolečina!", Toast.LENGTH_SHORT ).show();
               }

               if (progress <= 10 && progress >= 9) {
                   imageView.setImageResource( R.drawable.worst_pain );
                   Toast.makeText( getApplicationContext(), "Zelo močna bolečina!", Toast.LENGTH_SHORT ).show();
               }


               String strI = String.valueOf(progress);


           }

       } );


   }
    private void initializeVariables() {
        seekBar = (SeekBar) findViewById(R.id.seek_bar_id);
        textView = (TextView) findViewById(R.id.jakost_bolecin_id);
        //test = (TextView) findViewById(R.id.test);
        imageView=(ImageView)findViewById( R.id.slika_bolecine );

    }

    public void poslji (View view){

        String poslji_data = test.getText().toString().trim();
        String type ="Poslji";
        BackgroundWorker backgroundWorker = new BackgroundWorker(this);
        backgroundWorker.execute(type, poslji_data);
        }
}

似乎是 EventBus

的绝佳用例

SeekBarProgressBar 的子类,它有一个 getProgress() 方法。因此,您可以使用它来获取 poslji 方法中的当前进度。更改时无需跟踪进度。

docs所述:

A SeekBar is an extension of ProgressBar that adds a draggable thumb.