我用Ermodo Range Bar,而事實上,我需要顯示的最小值和以小時和分鐘的最大價值......這下面是:HH:MM在範圍杆
public class FilterActivity extends Activity {
private RangeBar rangebar;
final int SMALLEST_HOUR_FRACTION = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.filter_layout);
final TextView mDepartMin = (TextView)findViewById(R.id.tvDepartMin);
final TextView mDepartMax = (TextView)findViewById(R.id.tvDepartMax);
rangebar = (RangeBar) findViewById(R.id.rangebar1);
rangebar.setTickCount(25 * SMALLEST_HOUR_FRACTION);
rangebar.setTickHeight(0);
rangebar.setThumbRadius(8);
rangebar.setConnectingLineWeight(3);
mDepartMin.setText("" + (rangebar.getLeftIndex()/SMALLEST_HOUR_FRACTION) + ":" + SMALLEST_HOUR_FRACTION * (rangebar.getLeftIndex() % SMALLEST_HOUR_FRACTION));
mDepartMax.setText("" + (rangebar.getRightIndex()/SMALLEST_HOUR_FRACTION) + ":" + SMALLEST_HOUR_FRACTION * (rangebar.getRightIndex() % SMALLEST_HOUR_FRACTION));
rangebar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
@Override
public void onIndexChangeListener(RangeBar rangeBar, int leftThumbIndex, int rightThumbIndex) {
int minHour = leftThumbIndex/SMALLEST_HOUR_FRACTION;
int minMinute = SMALLEST_HOUR_FRACTION * (leftThumbIndex % SMALLEST_HOUR_FRACTION);
int maxHour = rightThumbIndex/SMALLEST_HOUR_FRACTION;
int maxMinute = SMALLEST_HOUR_FRACTION * (rightThumbIndex % SMALLEST_HOUR_FRACTION);
mDepartMin.setText(minHour + ":" + minMinute);
mDepartMax.setText(maxHour + ":" + maxMinute);
}
});
}
}
現在看起來是這樣的:
我想日期或日曆類可以幫助,但我如何使用它們?
我需要它顯示爲HH:MM,而不是H:M
閱讀'android.text.format.DateUtils'文檔 – pskink