How many days are left until Christmas Tutorials

Android Studio Tutorial How many days are left until Christmas 2018

Straightforward Tutorial step by step with free source code: rely days from the second you open the app until the settled date, in Android Studio version 3.1.three. For this tutorial, I counted the remaining days, hours, minutes and seconds until the Christmas 2018.

Create new challenge with Software identify: Days until Christmas; Minimal SDK: API 21 – Android 5 (Lollipop).

Add 2 footage, one for app background and one for countdown background, in res->drawable folder.

In manifest->AndroidManifest.xml write the code:








In app->res->values->strings.xml write the code:


Days until Christmas
There are only
until Christmas!

In app->res->layout->activity_main.xml write the code:








In app->java->MainActivity.java write the code:

package deal com.app.toyo.daysuntilchristmas;

import android.help.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity

personal TextView txtTimerDay, txtTimerHour, txtTimerMinute, txtTimerSecond;
personal TextView tvEvent;
personal Handler handler;
personal Runnable runnable;

@Override
protected void onCreate(Bundle savedInstanceState)
tremendous.onCreate(savedInstanceState);
setContentView(R.format.activity_main);

txtTimerDay = (TextView) findViewById(R.id.txtTimerDay);
txtTimerHour = (TextView) findViewById(R.id.txtTimerHour);
txtTimerMinute = (TextView) findViewById(R.id.txtTimerMinute);
txtTimerSecond = (TextView) findViewById(R.id.txtTimerSecond);
tvEvent = (TextView) findViewById(R.id.tvhappyevent);

countDownStart();

public void countDownStart()
handler = new Handler();
runnable = new Runnable()
@Override
public void run()
handler.postDelayed(this, 1000);
attempt
SimpleDateFormat dateFormat = new SimpleDateFormat(
“yyyy-MM-dd”);
// Please here set your event date//YYYY-MM-DD
Date futureDate = dateFormat.parse(“2018-12-25”);
Date currentDate = new Date();
if (!currentDate.after(futureDate))
lengthy diff = futureDate.getTime()
– currentDate.getTime();
lengthy days = diff / (24 * 60 * 60 * 1000);
diff -= days * (24 * 60 * 60 * 1000);
long hours = diff / (60 * 60 * 1000);
diff -= hours * (60 * 60 * 1000);
lengthy minutes = diff / (60 * 1000);
diff -= minutes * (60 * 1000);
lengthy seconds = diff / 1000;
txtTimerDay.setText(“” + String.format(“%02d”, days));
txtTimerHour.setText(“” + String.format(“%02d”, hours));
txtTimerMinute.setText(“”
+ String.format(“%02d”, minutes));
txtTimerSecond.setText(“”
+ String.format(“%02d”, seconds));

else
tvEvent.setVisibility(View.VISIBLE);
tvEvent.setText(“The event started!”);
textViewGone();

catch (Exception e)
e.printStackTrace();

;
handler.postDelayed(runnable, 1 * 1000);

public void textViewGone()
findViewById(R.id.LinearLayout10).setVisibility(View.GONE);
findViewById(R.id.LinearLayout11).setVisibility(View.GONE);
findViewById(R.id.LinearLayout12).setVisibility(View.GONE);
findViewById(R.id.LinearLayout13).setVisibility(View.GONE);
findViewById(R.id.textView1).setVisibility(View.GONE);
findViewById(R.id.textView2).setVisibility(View.GONE);

Run app in cellular gadget or Emulator (API 21 – Android 5) and see how many days are left until Christmas 2018, in format landscape.

Comply with video tutorial:

Obtain this app totally free and set up it on your cellular gadget to see how it works:
http://android-coffee.com/wp-content/uploads/projecs/DaysUntilChristmas2018.apk

Obtain challenge with Supply Code from here:
http://android-coffee.com/wp-content/uploads/projecs/DaysUntilChristmas2018.7z

Please subscribe right here to our YouTube channel. Thank you!
Examine subsequent tutorials to study all about Android.
For additional questions depart a message.