2017-03-23 3 views
0

問題が少し残っています。シークバーの価値をデータベースに伝えたいと思っています。どのように私は、その値がここで使用されるように得ることができます。データベースにシークバー値を保存する

このコードは一番下に再びです:

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); 
     } 
} 
+0

私がデータベースに入るのは0です –

答えて

0

SeekBarは、getProgress()メソッドを持つProgressBarのサブクラスです。したがって、あなたはposljiメソッド内で現在の進捗状況を取得するためにそれを使用することができます。その変化の進行状況を把握する必要はありません。 docsで述べたよう

シークバーをドラッグ親指を追加プログレスバーの拡張です。

関連する問題