2017-03-19 2 views
0

シークバーを特定のレベルにプッシュし、そのレベルがmysqlデータベースに保存されるシンプルなプログラムを作成しています。メソッドからシークバー値を取得して投稿するにはどうすればよいですか?私はアンドロイドのプログラミングに新しいので、私は立ち往生しています。ここの助けがあれば、大いに賛成するでしょう。mysqlデータベースにSeekBar値を渡す

私は現在、seekbarがint値で、文字列を使用しようとしているということを知っています。どのように文字列の代わりにintを使用するには、以下のpublic void posljiを変更する。

この部分(これは上記のコードから継続)に貼り付け
public class MainActivity extends AppCompatActivity { 



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


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

     seekBar = (SeekBar) findViewById(seek_bar_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(); 
       } 

       test.setText("" + 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 = seekBar.getText().toString(); 
      String type ="Poslji"; 
     BackgroundWorker backgroundWorker = new BackgroundWorker(this); 
     BackgroundWorker.execute(type,poslji_data); 
     } 
} 

答えて

0

int integerHere = Integer.parseInt(stringToConvert); 
関連する問題