Linear Layout in Android

A Layout that arranges its children in a single column or a single row. The direction of the row can be set by calling setOrientation(). You can also specify gravity, which specifies the alignment of all the child elements by calling setGravity() or specify that specific children grow to fill up any remaining space in the layout by setting the weight member of LinearLayout.LayoutParams.

The default orientation is horizontal. For more details Click Here

LinearLayout arrange its children in Horizontal View or Vertical View Only.

Example:


    

or


    
    
    
    

Here we not set any orientation so it will be “Horizontal” by default. This will show
Hello Android

If we set orientation “Vertical” then


    
    
    
    

It will show
Hello
Android

this means start layout and
this means end layout

android:layout_width=”match_parent”
this means: layout_width-> width of layout(Layout Parameter).
match_parent-> this will take width of screen.
if we set wrap_content-> then it will take width of children.
if we set fill_parent-> then it will take width of screen.

android:layout_height=”match_parent”
this means: layout_height-> height of layout(Layout Parameter).
match_parent-> this will take height of screen.
if we set wrap_content-> then it will take height of children.
if we set fill_parent-> then it will take height of screen.

Edit Text Android Tutorial

EditText Tutorial – – –

Here I will discuss all EditText Attributes.

This is for creating simple EditText



    


Add ems in EditText.This makes the EditText exactly 10 ems wide. An em width is the width of the widest (M) character in the selected font.



    


Create id in EditText. ID is necessary for each android widget because by id we will access in java code and apply operation on it.
like



    


Android Interview Questions with Answer for All

Here I am describing you some but important android interview questions. 

Question 1. What is PushNotification ?

Answer: Push Notification is a service which can be perform by GCM(Google Cloud Messaging). It helps developers send data from servers to their applications on Android devices. This is works on minimum android version 2.2. Before 27 June 2012, I called C2DM(Cloud to Device Messaging).

Question 2. What is Canvas? How it Works ?

Answer:  The Canvas class holds the “draw” calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing).

When you’re writing an application in which you would like to perform specialized drawing and/or control the animation of graphics, you should do so by drawing through a Canvas. A Canvas works for you as a pretense, or interface, to the actual surface upon which your graphics will be drawn — it holds all of your “draw” calls. Via the Canvas, your drawing is actually performed upon an underlying  Bitmap, which is placed into the window.

Question 3.  Describe Surface View ?

Answer: Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.

Question 4. What is View ?

Answer: This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.).

Question 5. Describe Viewgroup ?

Answer: The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.

Questions 6. Describe OpenGLES ?

Answer: OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware. OpenGL ES is a flavor of the OpenGL specification intended for embedded devices.

Question 7. Define types of Animation ?

Answer: These classes provide functionality for the property animation system, which allows you to animate object properties of any type. intfloat, and hexadecimal color values are supported by default.

  • Translate Animation
  • Alpha Animation
  • Rotate Animation
  • Scale Animation

Translate Animation: Translate Animation controls the position and location of a layout or button or any view on which animation is being applied. It can move an object either in x direction or y direction.

Alpha Animation: Alpha Animation is another type of Animation available for Android Programmers which controls the alpha level of any view. Alpha Animation is used to fade in and fade out a view.

Rotate Animation: An animation that controls the rotation of an object. This rotation takes place in the X-Y plane. You can specify the point to use for the center of the rotation, where (0,0) is the top left point. If not specified, (0,0) is the default rotation point.

Scale Rotation: An animation that controls the scale of an object. You can specify the point to use for the center of scaling.

Question 8. Define TimeInterpolator ?

Answer: A time interpolator defines the rate of change of an animation. This allows animations to have non-linear motion, such as acceleration and deceleration.

Question 9. What is Android API Level?

Answer: The API Level expressed by an application will be compared to the API Level of a given Android system, which may vary among different Android devices.

API Level is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform.

Question 10. What is WebView ?

Answer: A View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity. It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.

Question 11. Define SQLiteClosable ?

Answer: An object created from a SQLiteDatabase that can be closed. 

Question 12. Define SQLiteCursor ?

Answer: A Cursor implementation that exposes results from a query on a SQLiteDatabase. SQLiteCursor is not internally synchronized so code using a SQLiteCursor from multiple threads should perform its own synchronization when using the SQLiteCursor.

Question 13. Define SQLiteOpenHelper ?

Answer: A helper class to manage database creation and version management.

Question 14. Describe Adapter ?

Answer: An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.

Question 15. Define ArrayAdapter ?

Answer: A concrete BaseAdapter that is backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView. If you want to use a more complex layout, use the constructors that also takes a field id. That field id should reference a TextView in the larger layout resource.

Question 16. Classified the Web Service ?

Answer: Web services can be implemented in various ways. Web services can be classified as “Big” web services and “RESTful” web services.

  1. Big Web Service
  2. RESTful Web Service

Big Web Service: Big web services are based on SOAP standard and often contain a WSDL to describe the interface that the web service offers.

Big web services includes architecture to address complex non-functional requirements like transactions, security, addressing, trust, coordination, and also handles asynchronous processing and invocation.

Benefits of SOAP based Web Service…

  • Asynchronous processing
  • Reliability
  • Stateful operations

RESTful Web Service: RESTful web services are based on the way how our web works. REST— Representational State Transfer

REST is neither a standard nor a protocol. It is just an architectural style like say for example client-server architecture (client-server is neither a standard nor a protocol).

RESTful web services are based on HTTP protocol and its methods mainly PUT, GET, POST, and DELETE. These web services are better integrated with HTTP than SOAP-based services are, and as such do not require XML SOAP messages or WSDL service definitions.

Question 17. Difference Between HTTPGet and HTTPPost Method. 

Answer: HTTPGet is insecure way while HTTPPost is secure way to communicate with server.

In the HTTPGet, All the values that user sends to the server, embedded with the URL that we send as the request, where a third party can easily watch it. If I say it more technical way, by using the HTTP GET method, we are sending user details in the header part of the request not in the body.

In the HTTPPost, The reason is the content goes inside the body, not with the header as in GET method.I want to send some confidential data to a different server by using one of my native Android application.

Question 18. Describe Synchronous Task and Asynchronous Task.

Answer: In Synchronous Task , A program asks the system to perform a certain task, and then either waits or doesn’t wait for the task to finish.

AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called ParamsProgress and Result, and 4 steps, called onPreExecutedoInBackgroundonProgressUpdate and onPostExecute.

Question 19. Difference between Google Map V2 and Google Map V3 .

Answer: 

 

Introduction to Layout

In this tutorial we discuss about layouts.

A layout defines the visual structure for a user interface, such as the UI for an activity or app widget.
You can declare a layout in two ways:

Declare UI elements in XML: Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts.
Instantiate layout elements at runtime: Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.

For More Information about Layout  Click Here

 

Types of Layouts:  There are Basic Six Layout are following…

  1.  Linear Layout
  2.  Relative Layout
  3.  Table Layout
  4.  Grid View
  5.  Tab Layout
  6. List View

Setting Up with Android Studio

There are following steps to setting with android studio..

1. First I describe about jdk(How to install jdk) in my previous Post(Setting Up the Android Development Environment), so please follow it.

2. Now Copy Path bin folder like “C:\Program Files\Java\jdk1.7.0\bin”, and put in your system variable in your system
Please follow these steps are…
Go To computer prperties-
properties

now click on Advance System Setting-
system properties

now click on Environment Variable-
environment varaible
now, In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.

2. Now Go to following link and download Android Studio for windows.
http://developer.android.com/sdk/installing/studio.html
3. Now Extract this file and install android studio in any directory(as you select)

Setting Up Android Studio

There are following steps to setting with android studio..

1. First I describe about jdk(How to install jdk) in my previous Post(Setting Up the Android Development Environment), so please follow it.

2. Now Copy Path bin folder like “C:\Program Files\Java\jdk1.7.0\bin”, and put in your system variable in your system
Please follow these steps are…

Go To computer properties-

now click on Advance System Setting-

now click on Environment Variable-

now, In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.

now write-

now click OK again, while finish your all windows has been closed.

3. Now Go to following link and download Android Studio for windows.
http://developer.android.com/sdk/installing/studio.html
4. Now Extract this file and install android studio in any directory(as you select).
5. After installation successful , Run Android Studio Short Cut.
6. It will take few time and Will download some data from internet(downloading Gradle).
7. After finishing this, You can create your first project and run successfully.
8. Now enjoy with android studio. THANKS

First Simple Example

This is the basic and first example for starter android programmers. This example will show you that how to create first project and run your project. Please follow these steps with screen shots…

1. Open Eclipse.1

2. Now Click on this icon 2 then select Android application Project.
3

3. Type Application Name(Any), project name(if you want to change then can change according to your choice),package name(you can also change it according to your choice but remember package name should be start with com/net/org… ). If you want to change Minimum Required SDK and Target SDK then can change according to your requirement. Which device you want to compile your project and set theme for the project.And click on next.
4

4. Now you will see and click on Next.
5

5. Here you can change your application icon, background, shape and more. Then click on next.
6

6. Now you will see this screen. Again click on next.
7

7. Here you can change activity name, layout name and navigation type. Then click on finish.
8

8. After finish you will see.
9

9. Now create a AVD(Android Virtual Device) for running project, click on this icon10

10. After that you will see a window on your screen.
11

11. Click on New then you will see
12

12. Type AVD Name, select device(as screen size),choose Target, select camera from emulated, increase VM Heap Size like 256, type sd card size(If you want to take image from camera or creating database)
13 and then click OK.

13. Now you will see.
14 then click on start and close (if click on start then AVD Device will be shown and it will starting and if close screen then follow next).

14. Select Project want to run project and then click on this icon15 and select Android Application then ok 16or select project then right click on project and select Run As—> Android Application.

15. Now Virtual Device will be Start.

17

Next
18

Next
19

Final Result
20

Thanks for reading this tutorial.

Setting Up the Android Development Environment

1. Firstly download Java JDK from here.
2. Install JDK on your computer in default directory successfully.
3. Now download SDK bundle for your operating system from here.
4. Put this zip file into selected drives and extract there.
5. Create workspace folder for your programs.
6. Now open extracted file folder then open eclipse folder and run eclipse.
7. Crete Your first sample program and run.
8. Now create avd manager and create android virtual device and enjoy Android Application Development.

Posted in Uncategorized | 1 Reply