Skip to main content

Posts

Showing posts from September, 2018

Android UI controls

Android UI Controls There are number of UI controls provided by Android that allow you to build the graphical user interface for your app. Sr.No. UI Control & Description 1 TextView This control is used to display text to the user. 2 EditText EditText is a predefined subclass of TextView that includes rich editing capabilities. 3 AutoCompleteTextView The AutoCompleteTextView is a view that is similar to EditText, except that it shows a list of completion suggestions automatically while the user is typing. 4 Button A push-button that can be pressed, or clicked, by the user to perform an action. 5 ImageButton An ImageButton is an AbsoluteLayout which enables you to specify the exact location of its children. This shows a button with an image (instead of text) that can be pressed or clicked by the user. 6 CheckBox An on/off switch that can be toggled by the user. You should use check box when presenting users with a group of selectable options that are not mut...

Layout Attributes

Layout Attributes Each layout has a set of attributes which define the visual properties of that layout. There are few common attributes among all the layouts and their are other attributes which are specific to that layout. Following are common attributes and will be applied to all the layouts: Sr.No Attribute & Description 1 android:id This is the ID which uniquely identifies the view. 2 android:layout_width This is the width of the layout. 3 android:layout_height This is the height of the layout 4 android:layout_marginTop This is the extra space on the top side of the layout. 5 android:layout_marginBottom This is the extra space on the bottom side of the layout. 6 android:layout_marginLeft This is the extra space on the left side of the layout. 7 android:layout_marginRight This is the extra space on the right side of the layout. 8 android:layout_gravity This specifies how child Views are positioned. 9 android:layout_weight This s...

Android Layouts

Android Layout Types There are number of Layouts provided by Android which you will use in almost all the Android applications to provide different view, look and feel. Sr.No Layout & Description 1 Linear Layout LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. 2 Relative Layout RelativeLayout is a view group that displays child views in relative positions. 3 Table Layout TableLayout is a view that groups views into rows and columns. 4 Absolute Layout AbsoluteLayout enables you to specify the exact location of its children. 5 Frame Layout The FrameLayout is a placeholder on screen that you can use to display a single view. 6 List View ListView is a view group that displays a list of scrollable items. 7 Grid View GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid.

Custom Fonts

In android, you can define your own custom fonts for the strings in your application. You just need to download the required font from the internet, and then place it in assets/fonts folder. After putting fonts in the assets folder under fonts folder, you can access it in your java code through Typeface class. First , get the reference of the text view in the code. Its syntax is given below − TextView tx = ( TextView ) findViewById ( R . id . textview1 ); The next thing you need to do is to call static method of Typeface class  createFromAsset()  to get your custom font from assets. Its syntax is given below − Typeface custom_font = Typeface . createFromAsset ( getAssets (), "fonts/font name.ttf" ); The last thing you need to do is to set this custom font object to your TextView Typeface property. You need to call  setTypeface()  method to do that. Its syntax is given below − tx . setTypeface ( custom_font );

Alert dialog in android

A Dialog is small window that prompts the user to a decision or enter additional information. Some times in your application, if you wanted to ask the user about taking a decision between yes or no in response of any particular action taken by the user, by remaining in the same activity and without changing the screen, you can use Alert Dialog. In order to make an alert dialog, you need to make an object of AlertDialogBuilder which an inner class of AlertDialog. Its syntax is given below AlertDialog . Builder alertDialogBuilder = new AlertDialog . Builder ( this ); Now you have to set the positive (yes) or negative (no) button using the object of the AlertDialogBuilder class. Its syntax is alertDialogBuilder . setPositiveButton ( CharSequence text , DialogInterface . OnClickListener listener ) alertDialogBuilder . setNegativeButton ( CharSequence text , DialogInterface . OnClickListener listener ) Apart from this , you can use other functions provided b...

PHP - Sort Functions For Arrays

sort()  - sort arrays in ascending order rsort()  - sort arrays in descending order asort()  - sort associative arrays in ascending order, according to the value ksort()  - sort associative arrays in ascending order, according to the key arsort()  - sort associative arrays in descending order, according to the value krsort()  - sort associative arrays in descending order, according to the key PHP Global Variables - Superglobals Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. The PHP superglobal variables are: $GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION

Types of array

In PHP, there are three types of arrays: Indexed arrays  - Arrays with a numeric index Associative arrays  - Arrays with named keys Multidimensional arrays  - Arrays containing one or more arrays. PHP Indexed Arrays There are two ways to create indexed arrays: The index can be assigned automatically (index always starts at 0), like this: $cars = array("Volvo", "BMW", "Toyota"); or the index can be assigned manually: $cars[0] = "Volvo"; $cars[1] = "BMW"; $cars[2] = "Toyota"; The following example creates an indexed array named $cars, assigns three elements to it, and then prints a text containing the array values: Example <?php $cars =  array ( "Volvo" ,  "BMW" ,  "Toyota" ); echo   "I like "  . $cars[ 0 ] .  ", "  . $cars[ 1 ] .  " and "  . $cars[ 2 ] .  "." ; ?> PHP Associative Arrays Associative arrays are arrays...

PHP Arrays

An array stores multiple values in one single variable: Example <?php $cars =  array ( "Volvo" ,  "BMW" ,  "Toyota" ); echo   "I like "  . $cars[ 0 ] .  ", "  . $cars[ 1 ] .  " and "  . $cars[ 2 ] .  "." ; ?> What is an Array? An array is a special variable, which can hold more than one value at a time. If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this: $cars1 = "Volvo"; $cars2 = "BMW"; $cars3 = "Toyota"; However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300? The solution is to create an array! An array can hold many values under a single name, and you can access the values by referring to an index number. Create an Array in PHP In PHP, the  array()  function is used to create an array: array();

PHP Functions

PHP User Defined Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in a program. A function will not execute immediately when a page loads. A function will be executed by a call to the function. Syntax function  functionName () {     code to be executed ; } PHP Function Arguments Information can be passed to functions through arguments. An argument is just like a variable. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma. The following example has a function with one argument ($fname). When the familyName() function is called, we also pass along a name (e.g. Jani), and the name is used inside the function, which outputs several different first names, but an equal last name: Example <?php function  familyName($fname) { ...

Constants

A constant is a name or an identifier for a simple value. A constant value cannot change during the execution of the script. By default, a constant is case-sensitive. By convention, constant identifiers are always uppercase. A constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. If you have defined a constant, it can never be changed or undefined. To define a constant you have to use define() function and to retrieve the value of a constant, you have to simply specifying its name. Unlike with variables, you do not need to have a constant with a $. You can also use the function constant() to read a constant's value if you wish to obtain the constant's name dynamically. constant() function As indicated by the name, this function will return the value of the constant. This is useful when you want to retrieve value of a constant, but you do not know its name, i.e. It is stored in a variable or returned by a functi...

Variables

Variables The main way to store information in the middle of a PHP program is by using a variable. Here are the most important things to know about variables in PHP. All variables in PHP are denoted with a leading dollar sign ($). The value of a variable is the value of its most recent assignment. Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right. Variables can, but do not need, to be declared before assignment. Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters. Variables used before they are assigned have default values. PHP does a good job of automatically converting types from one to another when necessary. PHP variables are Perl-like. PHP has a total of eight data types which we use to construct our variables − Integers  − are whole numbers, without a decima...