Twitter Facebook Delicious Digg Stumbleupon Favorites More
Showing posts with label IMP. Show all posts
Showing posts with label IMP. Show all posts

Sunday, 3 June 2018

LAYOUT IN ANDROID


https://www.androidhive.info/2011/07/android-layouts-linear-layout-relative-layout-and-table-layout/

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

1. Linear Layout

In a linear layout, like the name suggests, all the elements are displayed in a linear fashion(below is an example of the linear layouts), either Horizontally or Vertically and this behavior is set in android:orientation which is an attribute of the node LinearLayout.

Example of Vertical layout snippet

<LinearLayout android:orientation="vertical"> .... </LinearLayout>
Example of Horizontal layout snippet

<LinearLayout android:orientation="horizontal"> .... </LinearLayout>
Android Layout

2. Relative Layout

In a relative layout every element arranges itself relative to other elements or a parent element.
As an example, lets consider the layout defined below. The “Cancel” button is placed relatively, to the right of the “Login” button parallely. Here is the code snippet that achieves the mentioned alignment (Right of Login button parallely)

Example code snippet

<Button android:id="@+id/btnLogin" ..></Button>

<Button android:layout_toRightOf="@id/btnLogin"
            android:layout_alignTop="@id/btnLogin" ..></Button>

3. Table Layout

Table layouts in Android works in the same way HTML table layouts work. You can divide your layouts into rows and columns. Its very easy to understand. The image below should give you an idea.

Table layout

<!-- Row 2 with 3 columns -->
    <TableRow 
        android:id="@+id/tableRow1" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent">  
        <TextView 
            android:id="@+id/TextView04" android:text="Row 2 column 1"
            android:layout_weight="1" android:background="#dcdcdc"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>  
        <TextView 
            android:id="@+id/TextView04" android:text="Row 2 column 2"
            android:layout_weight="1" android:background="#d3d3d3"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>
        <TextView 
            android:id="@+id/TextView04" android:text="Row 2 column 3"
            android:layout_weight="1" android:background="#cac9c9"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>
    </TableRow> 
Share:

Thursday, 31 May 2018

database imp things

MAIN DATABASE HANDLER CREATION

package com.example.viraj.grocery_list.Data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.example.viraj.grocery_list.Model.Grocery;
import com.example.viraj.grocery_list.Util.Constants;

import java.net.PortUnreachableException;
import java.util.List;

public class DatabaseHandler extends SQLiteOpenHelper {
    private Context ctx;

    public DatabaseHandler(Context context) {
        super(context, Constants.DB_NAME, null, Constants.DB_VERSION);
        this.ctx = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_GROCERY_TABLE = "CREATE TABLE " + Constants.TABLE_NAME + "("
                + Constants.KEY_ID + "INTEGER PRIMARY KEY,"
                + Constants.KEY_GROCERY_ITEM + "TEXT,"
                + Constants.KEY_QTY_NUMBER + "TEXT,"
                + Constants.KEY_DATE_NAME + "LONG);";
        db.execSQL(CREATE_GROCERY_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS" + Constants.TABLE_NAME);
        onCreate(db);
    }
    //---------------CRUD OPERATION CREATE READ UPDATE DELETE
//===========GROCERY CLASS KO IMPORT KIYA   ADD GROCERY
    public void  AddGrocery(Grocery grocery)
    {

    }
    //==========================GET A GROCERY
    private Grocery getgrocery(int id)
    {
return null;
    }
    //==========================GET A-L-L GROCERIES
    public List<Grocery> getAllGroceries()
    {
        return null;
    }
//========================= UPDATE GROCRIES
    public int updateGrocery(Grocery grocery)
    {
        return 0;
    }
    //=========================DELETE GROCERY
    public void deleteGrocery(int id)
    {

    }
    //=========================get count
    public int getGroceriesCount()
    {
        return 0;
    }
}

MAIN CONSTANTS

package com.example.viraj.grocery_list.Util;

import java.net.PortUnreachableException;

public class Constants {
    //table creation
    public static final int DB_VERSION = 1;
    public static final String DB_NAME = "groceryListDB";
    public static final String TABLE_NAME = "groceryTBL";

    //TABLE COLOUMS
public static final String KEY_ID="id";
public static final String KEY_GROCERY_ITEM="grocery_item";
public static final String KEY_QTY_NUMBER="quantity_number";
public static final String KEY_DATE_NAME="date_added";

}


MAIN MODEL  


package com.example.viraj.grocery_list.Model;

public class Grocery {
    private String name;
    private String quantity;
    private String dateItemAdded;
    private int id;

    //firstgrocery class ka object kiya he
    //second constructor
   // third getter and setter method

//empty constructor
    public Grocery() {
    }

    public Grocery(String name, String quantity, String dateItemAdded, int id) {
        this.name = name;
        this.quantity = quantity;
        this.dateItemAdded = dateItemAdded;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getQuantity() {
        return quantity;
    }

    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }

    public String getDateItemAdded() {
        return dateItemAdded;
    }

    public void setDateItemAdded(String dateItemAdded) {
        this.dateItemAdded = dateItemAdded;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}


Share:

Wednesday, 31 January 2018

imp xml

style.xml
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>

    </style>

</resources>



DIMENSION.XML 
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>


DIMENSION W820.XML

<resources>
    <!-- Example customization of dimensions originally defined in res/values/dimens.xml
         (such as screen margins) for screens with more than 820dp of available width. This
         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
    <dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

MAIN XML 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.londonappbrewery.destini.MainActivity"
    android:background="@drawable/background">



    <TextView
        android:id="@+id/storyTextView"
        android:text="@string/T1_Story"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="24sp"
        android:textColor="#ffffffff"
        />

    <Button
        android:id="@+id/buttonTop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/T1_Ans1"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="61dp"
        android:background="#e74c3c"
        android:textColor="#ecf0f1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textSize="15sp"
        />

    <Button
        android:id="@+id/buttonBottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/T1_Ans2"
        android:layout_alignParentBottom="true"
        android:layout_alignLeft="@+id/buttonTop"
        android:layout_alignStart="@+id/buttonTop"
        android:layout_alignRight="@+id/buttonTop"
        android:layout_alignEnd="@+id/buttonTop"
        android:background="#3498db"
        android:textColor="#ecf0f1"
        android:textSize="15sp"/>



</RelativeLayout>

Share:

Search This Blog

Popular Posts

Pages

how to make crores from 1 lakh in stock markets in 1 year

how to make crores from 1 lakh in stock markets in 1 year

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab