Tuesday, 18 October 2016

Adding a Custom CalendarView Using Android Studio to Highlight Event Dates

For the past six months or so I have been trying to add a calendar to my android app without success. I have the calendar widget that comes with Android Studio but that has limited functionality. I googled Custom CalendarView and found that Caldroid was the recommended custom calendar to use. However its not that easy to implement especially for a novice like myself. Then I stumbled upon CompactCalendarView by SundeepK which was easier to implement. It can be found at the link below:

https://github.com/SundeepK/CompactCalendarView

It only took 4 steps:

  • Add the dependency to the build.gradle app file
  • Add the CompactCalendarView widget to your XML layout file
  • Add the gist below to your main activity file
  • Run your program.




Below is a youtube video that helps you with the steps.





Monday, 10 October 2016

Converting From One Data Type to Another

Convert.ToXXX

XXX can be replaced by the .NET name of the type that we want to convert to.

Examples:

string age = "13"

int ageToInt = Convert.ToInt32(age);

when we check the value of ageToInt it should be 13;

We also have:

  • Convert.ToDouble();
  • Convert.ToBoolean();
  • Convert.ToInt16();
  • Convert.ToInt64();

Sunday, 9 October 2016

C# Objects part 1

Did you know that C# is an object oriented programming language (OOP)?


Computer programs are made up of objects that usually interact with each other. For example in a game you have an object called "hero" and this object "hero" may have to interact with an object called "villain". 

  • Objects have different attributes and behaviors.
  • When one is about to build software he should consider all the objects that he/she may need.
  • It is even possible that some of these objects could be reused in other programs.


Types of Objects:

  • int e.g 1, 2, 3, 100, 1000, -10000 (positive and negative whole numbers.
  • double e.g 2.234, 6.878, 75.55 (decimals)
  • string e.g "Hello World" (text enclosed by quotation marks)

Classes:

A class is a blueprint for making objects of a particular type. Doubles, ints and strings are examples of classes.

Classes contain attributes or things we call fields. Every field has an accessibility level which determines if it can be accessed outside of the class. A public keyword means that a field can be accessed from outside the class whereas a private keyword means that it cannot.

These fields can be accessed using dot notation.
e.g 

class Car {
public int NumberOfWheels;
private int NumberOfDoors

}

//Creating a car object
Car car = new Car();

//Using dot notation to give that car 4 wheels
car.NumberOfWheels = 4

Instances:

An instance of that class is an individual object of that particular class.

Lets say we had a class Car and we wanted to create a car object.





That is all there is to it!.


  • "Hello World" is an object of type string;
  • 4 is an object of type int;
  • 3.142 is an object of type double;

Constructors:

Constructor methods ensure that the fields in a class are filled out when we create an object by using a constructor method. Constructor methods are used to create instances of a class and they have the same name as the class that they are in(they are used to initialize an object).





Constructors do not return any values.