使用RecyclerView为我的Android应用程序创建30分钟的时隙

时间:2018-12-25 08:10:43

标签: android android-recyclerview

我正在创建一个Android应用,用户必须选择服务时段。我已经创建了这样的东西

from googletrans import Translator
import sys
translator = Translator()
f=open("T.txt","r").readlines()
for line in f:
    te=line 
    detected = translator.detect(te)
    srcv=detected.lang
    translated = translator.translate(te, src=srcv, dest='en')
    print(" Translated string:" + translated.text)

}

但是我是public class BookingTime extends AppCompatActivity { String bookedDate =""; RecyclerView.LayoutManager layoutManager; FirebaseRecyclerAdapter<BookingTimeModel,BookingTimeViewHolder> adapter; RecyclerView bookingTimeRecyc; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_booking_time); bookingTimeRecyc = findViewById(R.id.bookingTimeRecyc); layoutManager = new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false); bookingTimeRecyc.setLayoutManager(layoutManager); if (getIntent()!= null) bookedDate = getIntent().getStringExtra("booked"); getTimeSlots(); startRecyclerview(); } @Override protected void onStart() { super.onStart(); adapter.startListening(); } @Override protected void onStop() { super.onStop(); if (adapter != null) { adapter.stopListening(); } } private void startRecyclerview() { Query query = FirebaseDatabase.getInstance().getReference("DumyBookingTime"); FirebaseRecyclerOptions<BookingTimeModel> options = new FirebaseRecyclerOptions.Builder<BookingTimeModel>() .setQuery(query, BookingTimeModel.class) .build(); adapter = new FirebaseRecyclerAdapter<BookingTimeModel, BookingTimeViewHolder>(options) { @Override protected void onBindViewHolder(@NonNull BookingTimeViewHolder holder, int position, @NonNull BookingTimeModel model) { String timeValue=""; Date c = Calendar.getInstance().getTime(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); String currentDate = df.format(c); if (bookedDate.equals(currentDate)){ Date set = Calendar.getInstance().getTime(); SimpleDateFormat setdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); timeValue = setdf.format(set); }else { timeValue = bookedDate; } try { Calendar startCalender = Calendar.getInstance(); startCalender.setTime(df.parse(timeValue)); if (startCalender.get(Calendar.MINUTE )< 30){ startCalender.set(Calendar.MINUTE,30); }else { startCalender.add(Calendar.MINUTE,30); startCalender.clear(Calendar.MINUTE); } Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(startCalender.getTime()); endCalendar.add(Calendar.HOUR_OF_DAY,24 - startCalender.get(Calendar.HOUR_OF_DAY)); endCalendar.clear(Calendar.MINUTE); endCalendar.clear(Calendar.SECOND); endCalendar.clear(Calendar.MILLISECOND); SimpleDateFormat slotTime = new SimpleDateFormat("hh:mma"); while (endCalendar.after(startCalender)){ String slotStartTime = slotTime.format(startCalender.getTime()); startCalender.add(Calendar.MINUTE,30); String slotEndTime = slotTime.format(startCalender.getTime()); holder.startBookingTime.setText(slotStartTime); holder.endBookingTime.setText(slotEndTime); Log.d("DATE", slotStartTime + "- " + slotEndTime); } } catch (ParseException e) { e.printStackTrace(); } } @NonNull @Override public BookingTimeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.layout_booking_time, parent, false); return new BookingTimeViewHolder(view); } }; bookingTimeRecyc.setAdapter(adapter); adapter.notifyDataSetChanged(); } private void getTimeSlots() { String timeValue=""; Date c = Calendar.getInstance().getTime(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); String currentDate = df.format(c); if (bookedDate.equals(currentDate)){ Date set = Calendar.getInstance().getTime(); SimpleDateFormat setdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); timeValue = setdf.format(set); }else { timeValue = bookedDate; } try { Calendar startCalender = Calendar.getInstance(); startCalender.setTime(df.parse(timeValue)); if (startCalender.get(Calendar.MINUTE )< 30){ startCalender.set(Calendar.MINUTE,30); }else { startCalender.add(Calendar.MINUTE,30); startCalender.clear(Calendar.MINUTE); } Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(startCalender.getTime()); endCalendar.add(Calendar.HOUR_OF_DAY,24 - startCalender.get(Calendar.HOUR_OF_DAY)); endCalendar.clear(Calendar.MINUTE); endCalendar.clear(Calendar.SECOND); endCalendar.clear(Calendar.MILLISECOND); SimpleDateFormat slotTime = new SimpleDateFormat("hh:mma"); while (endCalendar.after(startCalender)){ String slotStartTime = slotTime.format(startCalender.getTime()); startCalender.add(Calendar.MINUTE,30); String slotEndTime = slotTime.format(startCalender.getTime()); } } catch (ParseException e) { e.printStackTrace(); } } 中的11:30 pm-12:00 pm的单个输出,但是在日志中却很完美。我也打算从时间上选择从先前活动中选择的日期。请帮我解决一下这个。我在哪里做错了?

0 个答案:

没有答案