How To Show The Current Time in TextView in Widget - android

I want to show the current time in updatable textView
I can't find the true way to make it
I want it to be updated every minute
Please anyone can help me ?
Thanks

Calendar cal = Calendar.getInstance();
SimpleDateFormat oSimpleDateFormat = new SimpleDateFormat("HH:mm:ss");
String MyString= oSimpleDateFormat.format(cal.getTime());
EditText oEditText =(EditText) findViewById(R.id.MyEdit);
oEditText.setText(MyString);
try this

You should use ScheduledThreadPoolExecutor.scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html

use the digital clock tag Digital Clock built in android studio 2.1.
Here it is built in tag to show time
< Digital Clock > don't use space b/w digital and clock, it was having problem while posting the answer.

Related

Change UI of Date Picker for Android TV app

I'm writing an android tv app with lean-back and I want to use android standard date picker and I want to make this like this pic
(eg: Made year part bigger when the user is selecting year and so on)
How can I achieve this?
You cannot use the standard date picker in Android TV apps because it was not designed for navigation using D-Pad. However, you can create your own widgets for day, month and year selection. You can simply use VerticalGridView to create them. For instance, you can do something similar to this for days:
<androidx.leanback.widget.VerticalGridView
android:id="#+id/vgv_days"
android:background="#color/transparent"
android:layout_marginEnd="10dp"
android:layout_width="40dp"
android:layout_height="35dp" />
customArrayObjectAdapterDays = new CustomArrayObjectAdapter(new DatePartPresenter(getContext()));
for (int i = 1; i < 31; i++) {
customArrayObjectAdapterDays.add(i);
}
vgvDays = (VerticalGridView) view.findViewById(R.id.vgv_days);
vgvDays.setNumColumns(1);
vgvDays.setAdapter(new ItemBridgeAdapter(customArrayObjectAdapterDays));
You also have to set the number of days (28, 29, 30, 31) depending on the year and selected month.

timepicker selected value text size [duplicate]

This question already has an answer here:
Implement iOS like time picker in Android
(1 answer)
Closed 5 years ago.
I want to change the selected text value size of a time picker.
Do we have any libraries for the same?
As I searched we do not have any customization in android. Need to develop a UI similar to iOS time picker.
For android brucetoo/PickView similar to IOS,
This is a helper lib for us to pick date or province like IOS system WheelView widget.
Added feature to pick time with WheelView Widget
Dependencies
compile 'com.brucetoo.pickview:library:1.2.3'
to use
DatePickerPopWin pickerPopWin = new DatePickerPopWin.Builder(MainActivity.this, new DatePickerPopWin.OnDatePickedListener() {
#Override
public void onDatePickCompleted(int year, int month, int day, String dateDesc) {
Toast.makeText(MainActivity.this, dateDesc, Toast.LENGTH_SHORT).show();
}
}).textConfirm("CONFIRM") //text of confirm button
.textCancel("CANCEL") //text of cancel button
.btnTextSize(16) // button text size
.viewTextSize(25) // pick view text size
.colorCancel(Color.parseColor("#999999")) //color of cancel button
.colorConfirm(Color.parseColor("#009900"))//color of confirm button
.minYear(1990) //min year in loop
.maxYear(2550) // max year in loop
.showDayMonthYear(true) // shows like dd mm yyyy (default is false)
.dateChose("2013-11-11") // date chose when init popwindow
.build();

Removing AM/PM in Android Time picker Widget

Is there any way to remove the AM/PM in a Time Picker Widget?
I have this function in my application but its purpose is to select only Hour and Minutes not including AM/PM, I tried to setIs24HourView(true) but it makes the time 24hours, I only want 12 hours.
It seems there is no public method in TimePicker to directly hide or show the AM/PM chooser. However, a look at the source code will give us the name of the resource ID for that View, which we can get with the system Resources. Then it's simply a matter of finding the View, and setting its visibility to GONE.
private void hideAmPmLayout(TimePicker picker) {
final int id = Resources.getSystem().getIdentifier("ampm_layout", "id", "android");
final View amPmLayout = picker.findViewById(id);
if(amPmLayout != null) {
amPmLayout.setVisibility(View.GONE);
}
}

Android: TimePicker setIs24HourView not working

I am trying to use the TimePicker in the 24 hour format and I am using setIs24HourView= true, but I am still not getting 24 hour format on the TimePicker. Here is my code in the onCreate of the Activity.
timePicker = (TimePicker) findViewById(R.id.timePicker1);
timePicker.setIs24HourView(true);
I even tried timePicker.setCurrentHour(cal.HOUR_OF_DAY) after setIs24HourView, but I am not able to see the 24 hour format on the TimePicker.
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="110dp" />
Am I missing anything here?
ok, I see what the problem is now.
It's not correctly setting the currentHour to the new 24 hour format, which is why you got 9:05 instead of 21:05. I'm guessing it isn't 9am where you are!
It is a bug, as mentioned in this question
seems the only work around, for now, is to do something like:
timePicker = (TimePicker) findViewById(R.id.timePicker1);
timePicker.setIs24HourView(true);
timePicker.setCurrentHour(Calendar.get(Calendar.HOUR_OF_DAY));
I see you tried cal.HOUR_OF_DAY, but didn't provide the code you actually used, but try this and see if it helps.
I notice this problem in jelly bean You can set the time to show in 24 hour view
TimePicker picker = (TimePicker) findViewById(R.id.timePicker1);
picker.setIs24HourView(true);
Calendar calendar = Calendar.getInstance();
int h = calendar.get(Calendar.HOUR_OF_DAY);
int m = calendar.get(Calendar.MINUTE);
picker.setCurrentHour(h);
picker.setCurrentMinute(m);
You can just use the device settings and thus let the user make this decision;
String clockType = android.provider.Settings.System.getString(context.getContentResolver(), android.provider.Settings.System.TIME_12_24);
setting timePicker.setCurrentHour(Calendar.get(Calendar.HOUR_OF_DAY)) solved the problem
timePicker = (TimePicker) findViewById(R.id.timePicker1);
timePicker.setIs24HourView(true);
We need to add this:
Calendar calendar = Calendar.getInstance();
timePicker.setCurrentHour(calendar.get(calendar.HOUR_OF_DAY));

Appcelerator Date picker without the days box calendar

Application type: mobile, Titanium SDK: 3.0, Platform & version: Android 4.1, Device: Samsung S3
when using the date picker i get a picker with three columns (day, month and year) but ALSO i am getting a calendar like box on the right containing the number of days. how can i remove the calendar box and keep the picker columns?? i am compiling against android 3.2 SDK
<android xmlns:android="http://schemas.android.com/apk/res/android">
<tool-api-level>13</tool-api-level>
<manifest>
<uses-sdk android:targetSdkVersion="13" android:minSdkVersion="13"/>
<!--
<uses-sdk android:minSdkVersion="10"/>
-->
</manifest>
</android>
my code:
var minDate = new Date();
var curMonth = 0;
for (var i = 0; i < 12; i++) {
curMonth = minDate.getMonth();
curMonth--;
minDate.setMonth(curMonth);
}
var now = new Date();
this.visitDatePicker = Ti.UI.createPicker({
type : Ti.UI.PICKER_TYPE_DATE,
maxDate : now,
value : now,
minDate : minDate,
selectionIndicator : true
});
i added a screenshot of what i mean, maybe i will get some replies :)
my problem is the box that appears on the right of the date picker, how can i get rid of it??
ok its a bug, see Android: Add calendarViewShown to picker TIMOB-12539 jira issue.
I spend more time debugging and optimizing titanium than actually writing code and business logic. my next project wont be using Titanium for sure....not acceptable

Categories

Resources