2016-05-06 2 views
0

私はErmodo Range Barを使用して、私は最小値と時間と分で最大値を表示する必要があるという事実が...それは以下の通りです:HH:レンジバーでMM

enter image description here

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); 
    } 
}); 
} 
} 

は、今では次のようになります。

enter image description here

私は、日付またはカレンダークラスが役立つかもしれないと思うが、どのように私はそれらを使用していますか?

私はそれがHHとして表示する必要があります代わりにHのMM:Mあなたが達成することができますDecimalFormatを使用

+0

read 'android.text.format.DateUtils' docs – pskink

答えて

1

。カレンダー

mDepartMin.setText(getFormattedDate(minHour,minMinute)); 

この方法

以下のコール
public static String getFormattedDate(int hour, int minute) { 
    Calendar cale = Calendar.getInstance(); 
    cale.set(Calendar.HOUR_OF_DAY, hour); 
    cale.set(Calendar.MINUTE, minute); 
    SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm"); 
    return dateFormat.format(cale.getTime()); 
} 

happyCodingを使用して

DecimalFormat deciFormat= new DecimalFormat("00"); 
mDepartMin.setText(deciFormat.format(minHour) + ":" + deciFormat.format(minMinute)); 

OR

+0

これは正しい方法ではないので、カレンダーまたは日付クラスを使用する必要があります。 –

+0

@KakshilShahは彼のコードを見ました。彼は 'Calendar'や' Date'インスタンスを使用していません。そして、主なものは 'minHours'、' minMiute'などの計算です。 – Bharatesh

+0

はい、彼は2日付(ちょうど時間がある)を使用してminとmaxを指すようにします。 –

関連する問題