I'm creating an app for a coffee shop which should display information about whether it is closed or open in a given time. The app should display either "OPEN" or "CLOSED" as a TextView
based on the time on user's device.
The coffee shop is open from 10:00:00 at morning and closed at 24:00:00 at night. Also, it is open from WED-SUN (MON and TUE closed).
For that, I created a TextView
layout in XML with empty text field:
<TextView
android:id="@+id/status_text_view"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
In java file I created a TextView
element and referred to the TextView
layout in the XML
file:
TextView textView = (TextView) findViewById(R.id.status_text_view);
I also fetched date and time from user's device by using:
String currentDateTimeString = java.text.DateFormat.getDateTimeInstance().format(new Date());
From here I don't know how to do the final task of displaying either "OPEN" or "CLOSED" in the TextView
layout based on date,time and day on the user's device. What I could do is only display the current date and time in the TextView
layout by using the code:
textView.setText(currentDateTimeString);
Note : If you share any code, kindly add comments describing each line of code as I'm a beginner level programmer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…