我想在这样的范围栏中显示时间。我希望其时间格式的最小值和最大值如HH:mm样式。我正在获得输出但不完美。我想从早上6点到晚上11:59设定我的价值。
我在哪里弄错了?我希望我的日期在15分钟间隔,如6:00 - > 6:15 - > 6:30 - > 6:45 ......等等
我所做的就是这里。
活动类
enter code // Gets the RangeBar
rangebar = (RangeBar) findViewById(R.id.rangebar1);
rangebar.setTickCount(25 * SMALLEST_HOUR_FRACTION);//SMALLEST_HOUR_FRACTION = 4;
rangebar.setTickHeight(0);
rangebar.setThumbRadius(8);
rangebar.setConnectingLineWeight(3);
// Sets the display values of the indices
rangebar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
@Override
public void onIndexChangeListener(RangeBar rangeBar, int leftThumbIndex, int rightThumbIndex) {
DecimalFormat deciFormat= new DecimalFormat("00");
leftIndexValue.setText("" + leftThumbIndex);
rightIndexValue.setText("" + 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);
leftIndexValue.setText(minHour + ":" + minMinute);
rightIndexValue.setText(maxHour + ":" + maxMinute);
leftIndexValue.setText(deciFormat.format(minHour) + ":" + deciFormat.format(minMinute));
rightIndexValue.setText(deciFormat.format(maxHour) + ":" + deciFormat.format(maxMinute));
}
});
这里
答案 0 :(得分:0)
设置setNotifyWhileDragging选项
rangebar = (RangeBar) findViewById(R.id.rangebar1);
rangebar.setTickCount(25 * SMALLEST_HOUR_FRACTION);//SMALLEST_HOUR_FRACTION = 4;
rangebar.setTickHeight(0);
rangebar.setThumbRadius(8);
rangebar.setConnectingLineWeight(3);
rangebar.setNotifyWhileDragging(true);
并设置onRangeSeekBarValuesChanged Listener
rangebar.setOnRangeSeekBarChangeListener(new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
@Override
public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
// set bar value And Text
}
});
答案 1 :(得分:0)
我认为根据拇指指数计算小时和分钟是错误的。有一个适当的计算:
hours = thumb / SMALLEST_HOUR_FRACTION; // SMALLEST_HOUR_FRACTION should be defined as int
minute = (thumb % SMALLEST_HOUR_FRACTION) * (60 / (float) SMALLEST_HOUR_FRACTION);
我相信您应该将最大范围指定为rangebar.setTickCount(24 * SMALLEST_HOUR_FRACTION); (每天24小时)。
但是有一种更好的格式化日期和时间的方法。看一下Calendar和SimpleDateFormat类:Android Format calendar to output time