我正在编写一个简单的程序,用户将搜索栏推送到某个级别,然后将该级别保存到mysql数据库中。如何从方法中获取搜索栏值并发布?我很困难,因为我是Android编程的新手。这里的任何帮助都会受到很大的限制。
我知道目前的问题是搜索栏是int值,我正在尝试使用字符串。如何更改以下public void poslji以使用int而不是string。
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 :(得分:0)
要将String转换为整数使用:
int integerHere = Integer.parseInt(stringToConvert);