プログレスバーで説明するが, シークバーでも同様に値の設定及び取得が行える.
- ProgressBar01.java
- findViewByIdメソッドで, チェック状態が変化したIDに対応したプログレスバーのインスタンスを取得する.
- ProgressBar#setMax/getMaxメソッドで, 最大値の設定及び取得を行う.
- ProgressBar#setProgress/getProgressメソッドで, プログレスバーの値の設定及び取得を行う.
- ProgressBar#setSecondaryProgress/getSecondaryProgressメソッドで, セカンダリー値の設置及び取得を行う.
package com.moonlight_aska.android.progressbar01;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ProgressBar;
public class ProgressBar01 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ProgressBar progBar = (ProgressBar)findViewById(R.id.progbar01_id);
// 最大値の設定及び取得
progBar.setMax(100);
int max = progBar.getMax();
// プログレスバーの値の設定及び取得
progBar.setProgress(50);
int current = progBar.getProgress();
// セカンダリー値の設定及び取得
progBar.setSecondaryProgress(70);
int secondary = progBar.getSecondaryProgress();
}
}