ホイールの4行すべてから値を取得し、その値をテキストビューまたはトーストに表示したいと思います。私のtestwheelvalue(、)メソッドは、ホイールの表面から値を取得し、その値をメソッドtestpin()に返すことを想定しています。testpin()が値をv1-v4に格納した後、メソッドupdatestatus()は値の合計をテキストフィールドに表示する必要があります。
パブリッククラスPasswActivityはActivity{を拡張します
int testpins;
int v1 = 0;
int v2 = 0;
int v3 = 0;
int v4 = 0;
TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.passw_layout);
initWheelday(R.id.passw_1);
initWheelhour(R.id.passw_2);
initWheelmin(R.id.passw_3);
initWheelsec(R.id.passw_4);
updateStatus();
}
// Wheel scrolled flag
private boolean wheelScrolled = false;
// Wheel scrolled listener
OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {
public void onScrollingStarted(WheelView wheel) {
wheelScrolled = true;
}
public void onScrollingFinished(WheelView wheel) {
wheelScrolled = false;
updateStatus();
}
};
// Wheel changed listener
private OnWheelChangedListener changedListener = new OnWheelChangedListener() {
public void onChanged(WheelView wheel, int oldValue, int newValue) {
if (!wheelScrolled) {
updateStatus();
}
}
};
/**
* Updates entered PIN status
*/
private void updateStatus() {
text = (TextView) findViewById(R.id.pwd_status);
testPin();
text.setText(String.valueOf(testpins));
// Toast.makeText(getBaseContext(), testpins,
// Toast.LENGTH_SHORT).show();
}
/**
* Initializes wheel
*
* @param id
* the wheel widget Id
*/
private void initWheelsec(int id) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new NumericWheelAdapter(this, 0, 59, "%02d"));
wheel.setCurrentItem((int) (Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(false);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}
private void initWheelmin(int id) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new NumericWheelAdapter(this, 0, 59, "%02d"));
wheel.setCurrentItem((int) (Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(false);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}
private void initWheelhour(int id) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new NumericWheelAdapter(this, 0, 23, "%02d"));
wheel.setCurrentItem((int) (Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(false);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}
private void initWheelday(int id) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new NumericWheelAdapter(this, 0, 5, "%02d"));
wheel.setCurrentItem((int) (Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(false);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}
/**
* Returns wheel by Id
*
* @param id
* the wheel Id
* @return the wheel with passed Id
*/
private WheelView getWheel(int id) {
return (WheelView) findViewById(id);
}
/**
* Tests entered PIN
*
* @param v1
* @param v2
* @param v3
* @param v4
* @return true
*/
private void testPin() {
v1 testWheelValue(R.id.passw_1, v1);
v2 testWheelValue(R.id.passw_2, v2);
v3 testWheelValue(R.id.passw_3, v3);
v4 testWheelValue(R.id.passw_4, v4);
testpins = v1 + v2 + v3 + v4;
}
/**
* Tests wheel value
*
* @param id
* the wheel Id
* @param value
* the value to test
* @return true if wheel value is equal to passed value
*/
private int testWheelValue(int id, int value) {
int wheel = getWheel(id).getCurrentItem();
wheel = value;
text.setText(String.valueOf(testpins));
return wheel;
}
}