Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created July 12, 2022 06:14
Show Gist options
  • Save codeforfun-jp/88f637925d1a49ee4865305fd6613a0f to your computer and use it in GitHub Desktop.
Save codeforfun-jp/88f637925d1a49ee4865305fd6613a0f to your computer and use it in GitHub Desktop.
【Java】How to Use SeekBar 5
package com.example.seekbarsample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textView);
SeekBar seekbar = findViewById(R.id.seekbar);
Button button = findViewById(R.id.button);
// 初期値を表示
textView.setText(seekbar.getProgress() + "");
// 「リセット」を押したら50にする
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
seekbar.setProgress(50);
}
});
// SeekBarイベント
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
textView.setText(i + "");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment