我有点陷入困境。我想将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);
}
}
答案 0 :(得分:0)
似乎是EventBus
的绝佳用例答案 1 :(得分:0)
SeekBar
是ProgressBar
的子类,其getProgress()方法。因此,您可以使用它来获取poslji
方法中的当前进度。无需在变化时跟踪进度。
如docs中所述:
SeekBar是ProgressBar的扩展,它添加了一个可拖动的拇指。