Wednesday, April 11, 2018

What is a Member Variable in Android?


First If you need to Clear ourself What is a Class Variable or Static Variable and Instance variable.Read the below link for explanation

Static-variable-vs-instance-variable-in Android

Now What is a member Variable?

Member Variable is not a type of variable, Its a naming convention used in a class.

if the variable defined is a member of a class, we define its as member variable, Its done by prefixing the variable name with "m". There is nothing wrong if we don't follow, but android guidelines insist following this methodology for identification.


Static Variable vs Instance Variable in Android Explained

Variables can be Static or Instance Variable depending upon our usage.

Suppose the value is constant throughout the class we can define a static variable

In case the value of variable keeps changing every time we call the class then its is called as Instance variable



Example we have a class called bus

if there is a variable defined for driver and passengers

bus1

the value of driver is always =1 so we can define as static

           public int static driver=1;

the value of passenger keeps changing so its defined as instance

         public int passenger=20;

again for bus2

the value of driver is always =1 so we can define as static

           public int static driver=1;

the value of passenger keeps changing so its defined as instance

         public int passenger=30;


Tuesday, April 10, 2018

What Is a Class?

In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. class is the blueprint from which individual objects are created.
The following Bicycle class is one possible implementation of a bicycle:
class Bicycle {


    int cadence = 0;                            
    int speed = 0;                              STATE OFTHE OBJECT
    int gear = 1;                               



    void changeCadence(int newValue) {          
         cadence = newValue;                    METHOD OF INTERACTION
    }                                           

    void changeGear(int newValue) {             
         gear = newValue;                       METHOD OF INTERACTION
    }                                           

    void speedUp(int increment) {               
         speed = speed + increment;             METHOD OF INTERACTION
    }                                           

    void applyBrakes(int decrement) {           
         speed = speed - decrement;             METHOD OF INTERACTION
    }                                           

    void printStates() {                        
         System.out.println("cadence:" +        
             cadence + " speed:" +              METHOD OF INTERACTION
             speed + " gear:" + gear);          
    }                                           
}

Here's a BicycleDemo class that creates two separate Bicycle objects and invokes their methods:
class BicycleDemo {
    public static void main(String[] args) {

        // Create two different 
        // Bicycle objects
        Bicycle bike1 = new Bicycle();   
        Bicycle bike2 = new Bicycle();   

        // Invoke methods on 
        // those objects
        bike1.changeCadence(50);
        bike1.speedUp(10);
        bike1.changeGear(2);
        bike1.printStates();

        bike2.changeCadence(50);
        bike2.speedUp(10);
        bike2.changeGear(2);
        bike2.changeCadence(40);
        bike2.speedUp(10);
        bike2.changeGear(3);
        bike2.printStates();
    }
}

The output of this test prints the ending pedal cadence, speed, and gear for the two bicycles:
cadence:50 speed:10 gear:2
cadence:40 speed:20 gear:3

Sunday, April 8, 2018

What does LayoutInflater class do?



java.lang.Object
   ↳android.view.LayoutInflater

layout inflater is a java class that extends object


There are two ways in which we can make a view (textView, imageView, ...,),

First we create the view in Xml and then call the same in Java by findViewById method.


Second using the LayoutInflater here we get the layout and define the views.

The first one is simple and is used only to display few textView,imageView....,

If the list of item is large, we need to use the inflater method to reduce the code and also to reduce
 the memory consumed.


Instantiates a layout XML file into its corresponding View objects. It is never used directly. Instead, use getLayoutInflater() orgetSystemService(Class) to retrieve a standard LayoutInflater instance
 that is already hooked up to the current context and correctly configured for the device you are
running on. when you run setContentView(layout file name), you can run findViewById(id of the widget).
          You dont need to do something like xyz.findViewById. The context of your app is set to that

layout file and all findBiewById call will refer to that layout file.There are cases when you need to pick up one more layout file, like a CustomDialog, ListElement  or a Custom Toast. At this time you wont want to create a Activity just for these small UI
components, that that time you programmatically need to get a programmatic reference to your
layout file, so that you can run findViewById on it.



Saturday, April 7, 2018

Introduction

This blog is a learning pathway for someone interested in developing Android apps. Though a lot of resources are available in developer.android.com and stackoverflow for developing a successful app. Here I would like to share my journey, hardships faced during my Android app development.
I will be sharing the codes and with explaination to help a beginner.