Thursday, 11 December 2014

Complete JSON parsing in Android Application for Beginners


JSONHandler.java

package com.rakesht.json;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

/**
 * Adds the ability to JSON Lib (in Android) to parse JSON data into Bean Class. It
 * is based on Android's (org.json.*)
 *
 * @author
 *
 */
public class JSONHandler {

    String TAG = "My App";
   

Database CRUD Operation in Android Application Development

SQliteDataBaseActivity.java

package com.rakesh.tiwari.sqlitedatabase;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class SQliteDataBaseActivity extends Activity {
    Contact contact;
    ListView listView;

    ArrayList<HashMap<String, String>> contactList;
    AyArrayAdapter ayArrayAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        contactList = new ArrayList<HashMap<String, String>>();

        final Button btnInsert = (Button) findViewById(R.id.btn_insert);
        final Button btnSelect = (Button) findViewById(R.id.btn_select);
        final Button btnSelectall = (Button) findViewById(R.id.btn_selectall);
        final Button btnUpdate = (Button) findViewById(R.id.btn_update);
        final Button btnDelete = (Button) findViewById(R.id.btn_delete);

        final EditText edtId = (EditText) findViewById(R.id.editTextId);
        final EditText edtName = (EditText) findViewById(R.id.editTextName);
        final EditText edtEmail = (EditText) findViewById(R.id.editTextEmail);

        final DBAdapter dba = new DBAdapter(this);

        // Insert
        // Contact------------------------------------------------------------------------

        btnInsert.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dba.open();
                contact = new Contact();
                contact.setName(edtName.getText().toString());
                contact.setAddress(edtEmail.getText().toString());
                dba.insertContact(contact);
                dba.close();
                edtName.setText("");
                edtEmail.setText("");
                Toast.makeText(getApplicationContext(), "Inserted",
                        Toast.LENGTH_LONG).show();
                Intent i = new Intent(SQliteDataBaseActivity.this,
                        SQliteDataBaseActivity.class);
                startActivity(i);
            }
        });
        // Select all
        // contacts----------------------------------------------------------------------------

        btnSelectall.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                getData();
                /*
                 * dba.open(); Cursor c=dba.getAllContacts();
                 * if(c.moveToFirst()){ do{ DisplayContact(c);
                 * }while(c.moveToNext()); } dba.close();
                 */
            }

            /*
             * private void DisplayContact(Cursor c){
             * Toast.makeText(getApplicationContext(),
             * "id: "+c.getString(0)+"\n"+"Name: "+c.getString(1)+"\n"+
             * "Email: "+c.getString(2), Toast.LENGTH_LONG).show();
             *
             * }
             */

            /*
             * private void DisplayContact(Cursor c){
             * Toast.makeText(getApplicationContext(),
             * "Name: "+c.getString(0)+"\n"+ "Email: "+c.getString(1),
             * Toast.LENGTH_LONG).show();
             *
             * }
             */
        });

        // Select a
        // contact----------------------------------------------------------------------

        btnSelect.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dba.open();
                Cursor c = dba.getContact(Integer.parseInt(edtId.getText()
                        .toString()));
                if (c.moveToFirst()) {
                    DisplayContact(c);
                } else {
                    Toast.makeText(getApplicationContext(), "No contact found",
                            Toast.LENGTH_LONG).show();
                }
                dba.close();

            }

            private void DisplayContact(Cursor c) {
                Toast.makeText(
                        getApplicationContext(),
                        "id: " + c.getString(0) + "\n" + "Name: "
                                + c.getString(1) + "\n" + "Email: "
                                + c.getString(2), Toast.LENGTH_LONG).show();
            }
        });

        // Update a
        // contact----------------------------------------------------------------------

        btnUpdate.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dba.open();
                if (dba.updateContact(Integer.parseInt(edtId.getText()
                        .toString()), edtName.getText().toString(), edtEmail
                        .getText().toString()))
                    Toast.makeText(getApplicationContext(),
                            "Update successful", Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(getApplicationContext(), "Update failed",
                            Toast.LENGTH_LONG).show();
                dba.close();
                Intent i = new Intent(SQliteDataBaseActivity.this,
                        SQliteDataBaseActivity.class);
                startActivity(i);
            }
        });

        // Delete
        // contact------------------------------------------------------------------------------

        btnDelete.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dba.open();
                dba.deleteContact(Integer.parseInt(edtId.getText().toString()));
                dba.close();
            }
        });
    }

    public void getData() {

        DBAdapter dbAdapter = new DBAdapter(SQliteDataBaseActivity.this);
        dbAdapter.open();

        Cursor c = dbAdapter.getAllContacts();
        c.moveToFirst();

        while (!c.isAfterLast()) {
            HashMap<String, String> map = new HashMap<String, String>();

            map.put("name", c.getString(c.getColumnIndex(DBAdapter.KEY_NAME)));
            map.put("address",
                    c.getString(c.getColumnIndex(DBAdapter.KEY_EMAIL)));

            c.moveToNext();

            contactList.add(map);
        }

        c.close();
        dbAdapter.close();

        listView = (ListView) findViewById(R.id.Listview);
        ayArrayAdapter = new AyArrayAdapter(SQliteDataBaseActivity.this,
                R.layout.name_list, contactList);
        listView.setAdapter(ayArrayAdapter);
    }

    public class AyArrayAdapter extends ArrayAdapter<HashMap<String, String>> {
        public AyArrayAdapter(Context handler, int textViewResourceId,
                ArrayList<HashMap<String, String>> contactList) {
            super(handler, textViewResourceId, contactList);
        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {

            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View rowView = inflater.inflate(R.layout.name_list, null);

            TextView name = (TextView) rowView.findViewById(R.id.textViewname);
            name.setText(contactList.get(position).get("name"));

            TextView modelenumber = (TextView) rowView
                    .findViewById(R.id.textViewaddresas);
            modelenumber.setText(contactList.get(position).get("address"));

            return rowView;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sqlite_data_base, menu);
        return true;
    }

}


Contact.java

package com.rakesh.tiwari.sqlitedatabase;

import java.io.Serializable;

@SuppressWarnings("serial")
public class Contact implements Serializable {
    private String name, address;

    public String getName() {
        return name;
    }

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

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

}

DBAdapter.java

package com.rakesh.tiwari.sqlitedatabase;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBAdapter {

    public static final String KEY_ROWID = "id";
    public static final String KEY_NAME = "name";
    public static final String KEY_EMAIL = "email";
    private static final String TAG = "DBAdapter";
    private static final String DATABASE_NAME = "myDB";
    private static final String DATABASE_TABLE = "contacts";
    private static final int DATABASE_VERSION = 1;
    /*public static final String DATABASE_CREATE = "create table contacts(id integer primary key autoincrement,"
            + "" + " name text not null,email text not null);";*/
    private static final String DATABASE_CREATE = "create table contacts(id integer primary key autoincrement, name text not null, email text not null);";

    private final Context context;
    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    // Create construstor...............

    public DBAdapter(Context cntx) {
        this.context = cntx;
        DBHelper = new DatabaseHelper(context);

    }

    private static class DatabaseHelper extends SQLiteOpenHelper {

        public DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            // TODO Auto-generated constructor stub
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            try {
                db.execSQL(DATABASE_CREATE);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            Log.w(TAG, "Upgrading Database from version" + oldVersion + "to"
                    + newVersion + ",which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS contacts");
            onCreate(db);
        }

    }

    // --- open the database----------------

    public DBAdapter open() throws SQLException {

        db = DBHelper.getWritableDatabase();
        return this;

    }

    // --- close database---------------------------------------------------

    public void close() {
        DBHelper.close();
    }

    // ----- Insert a contact into the
    // database---------------------------------------
    public long insertContact(Contact contact) {

        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_NAME, contact.getName());
        initialValues.put(KEY_EMAIL, contact.getAddress());
        return db.insert(DATABASE_TABLE, null, initialValues);
    }

    // Delete a particular
    // contact--------------------------------------------------------------

    public boolean deleteContact(long rowId) {

        return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }

    // Retrieve all
    // contacts.....................................................................

    public Cursor getAllContacts() {
        /*return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_NAME ,KEY_EMAIL
                }, null, null, null, null, null);*/
        return db.query(DATABASE_TABLE, new String[] { KEY_NAME ,KEY_EMAIL
        }, null, null, null, null, null);


    }

    // retrieve a particular
    // contact.........................................................................

    public Cursor getContact(long rowId) throws SQLException {

        Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
                KEY_ROWID, KEY_NAME, KEY_EMAIL }, KEY_ROWID + "=" + rowId,
                null, null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();

        }
        return mCursor;
    }

    // Update a
    // contact-----------------------------------------------------------------------------------

    public boolean updateContact(long rowID, String name, String email) {
        ContentValues cValue = new ContentValues();
        cValue.put(KEY_NAME, name);
        cValue.put(KEY_EMAIL, email);
        return db.update(DATABASE_TABLE, cValue, KEY_ROWID + "=+rowId", null) > 0;

    }

}

main.xml

<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=".SQliteDataBaseActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="SQLite DataBase"
        android:textColor="#336633"
        android:textSize="20dp"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/editTextId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="10dp"
       android:inputType="number"
       android:hint="ID"
        android:ems="5" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editTextName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="10dp"
        android:inputType="textPersonName"
        android:hint="Name"
        android:ems="5" />

    <EditText
        android:id="@+id/editTextEmail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="60dp"
        android:inputType="textEmailAddress"
        android:hint="Email"
        android:ems="8" />

    <Button
        android:id="@+id/btn_insert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editTextEmail"
        android:layout_marginTop="22dp"
        android:text="Insert" />
    <ListView
        android:id="@+id/Listview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btn_insert"
        >
    </ListView>

    <Button
        android:id="@+id/btn_select"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/btn_insert"
        android:layout_alignBottom="@+id/btn_insert"
        android:layout_alignLeft="@+id/editTextName"
        android:text="Select" />

    <Button
        android:id="@+id/btn_selectall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/btn_insert"
        android:layout_below="@+id/btn_insert"
        android:layout_marginTop="58dp"
        android:textSize="15sp"
        android:text="Select All" />
  

    <Button
        android:id="@+id/btn_update"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/btn_selectall"
        android:layout_alignLeft="@+id/btn_select"
        android:text="Update" />

    <Button
        android:id="@+id/btn_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn_update"
        android:layout_marginTop="34dp"
        android:layout_toLeftOf="@+id/btn_update"
        android:text="Delete" />

</RelativeLayout>

name_list.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textViewname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

    <TextView
        android:id="@+id/textViewaddresas"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="3dp"
        android:text="" />

</LinearLayout>

Monday, 8 December 2014

Custom ListView and ListItem Detail with Text and Image Example in Android Apps

 Custom ListView and List Item Detail

MainActivity.java

package com.rakesht.customlistview;

import java.util.ArrayList;
import java.util.HashMap;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

Sunday, 21 September 2014

How to Integrate AdMob in Android Application

What is Admob?
AdMob is the Google product which is featured with display advertisement on mobile Apps by integrating with applications like Google AdSense for websites. It's not only for Android apps also featured for iOS and Windows Phone 8.

For more details follow below link.
Guide for AdMobe

For android go through Android Quick Start .
Develop using Eclipse IDE follow https://developer.android.com/training/monetization/ads-and-ux.html

Develop using Android Studio follow https://developer.android.com/training/monetization/ads-and-ux.html

To integrate AdMob in android applications first of all you need to update GooglePlayService through follow below steps.
Step-1:
Open your Eclipse IDE Window->open "Android SDK Manager"-> Extras and install Google Play Services

Step-2:
import "google play service"  which will be in android SDK (android-sdk-windows\extras\google\google_play_services).

Step-3:
 Integrate android AdMob SDK using "add external JAR" Right Click on project click on properties->Java Build Path->Libraries->click on "Add External JARs" using this path "android-sdk-windows\extras\google\admob_ads_sdk".


Thursday, 10 April 2014

ViewAnimator Creation in Android Application



main.xml

<LinearLayout 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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="View Animator"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />


Wednesday, 9 April 2014

ViewSwitcher Functionality in Android Application Development



main.xml


<LinearLayout 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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="View Switcher"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />

Tuesday, 8 April 2014

How to Switch Data Using TextSwitcher Widget in Android Apps


This blog describe about TextSwitcher functionality in android application development. Using TextSwitcher widget can get next and previous data by click on next and prev button.


main.xml


<LinearLayout 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:orientation="vertical" >

Monday, 7 April 2014

How to Create StackView in Android Application Development

This blog is describe about StackView functionality. This functionality depend upon Last in-First out or First in-Last out data structure activity.This means when we open 1st activity and then open 2nd activity, then 3rd activity, 3rd activity will in front and other 1st and 2nd activity will run in background. After click on back button 3rd activity will destroy and 2nd activity will resume. Similarly again clivk on back button 2nd activity will destroy and 1st activity will resume this functionality is also known as "Back Stack" functionality in Android.

main.xml


Tuesday, 1 April 2014

Touch Event ViewFlipper Functionality in Android Application Development

This blog describe about ViewFlipper functionality in android app development. Through ViewFlipper widget can navigate from one view to another view by click event or touch event also. Through click event need Next and Previous button. through touch event need to create four animation file within animation folder.

Fundamental of touch event with X and Y co-ordinate:
onTouchEvent () method  called when User performs any touch event on screen
when a User swaps from Left to Right or Right to left
user first touches on the screen ( lets say first x coordinate is x1) holds ,swaps  then leaves the screen  (lets say second x coordinate is x2)





so if x2> x1  it means Left to Right sweep has been performed and
     if x2<x1   it means Right to Left sweep has been performed

Similarly we can track UP to Down and Down to UP swap

if  y2> y1  it means UP to Down sweep has been performed and
if  y2<y1   it means Down to UP sweep has been performed




main.xml


<LinearLayout 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:orientation="vertical" >

Monday, 31 March 2014

ImageSwitter Functionality Creation in Android Apps


This blog describe about ImageSwitcher view of image gallery.

main.xml


<LinearLayout 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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Simple Image Switcher"
        android:layout_gravity="center"
        android:textSize="20sp"
        android:layout_marginTop="10dp"
        android:textColor="#336633"
        android:textStyle="bold"/>

Saturday, 29 March 2014

WebView Functionality in Android Application Development


This blog about WebView creation in android apps development.

main.xml


<LinearLayout 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:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Web View"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />

TabWidget HorizontalScrollView Functionality Using TabHost in Android Applications


In android applications TabWidget functionality is very useful feature. It help to quick tab navigation using HorizontalScrollView and display tab relevant screen.


main.xml


<LinearLayout 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:orientation="vertical" >

Thursday, 27 March 2014

Simple SlidingDrawer Functionality in Android Application Development

This blog described about most popular android feature sliding between two screen using tab or menu list icon. This feature can performed by using SlidingDrawer widget in android app it can be slide manually also.
Below is the simple code of SlidingDrawer functionality.

main.xml

<LinearLayout 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:orientation="vertical"   
     >

Wednesday, 26 March 2014

SearchView Functionality in Android Apps

When user want to get data from a list data quickly SearchView widget in android assist the user by filtering according to alphabet character or position of data. This blog describe about simple static search view functionality.



main.xml

<LinearLayout 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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Search View"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_marginTop="20dp"
        android:layout_gravity="center"/>

Tuesday, 25 March 2014

HorizontalScrollView Creation in Android Apps

Some time android app need horizontal scroll view to complete this requirement can use HorizontalScrollView widget and implement in app.

main.xml

<LinearLayout 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:orientation="vertical" >

Monday, 24 March 2014

Simple ScrollView Creation in Android Apps Development

This blog is relevant to ScrollView creation in android application when size of data is more than screen's height of device. To populate large data in small screen device need scroll view. To create scroll view need ScrollView layout with single parent linearLayou or RelativeLayout. Can't include more than one linear or relative layout within scrollView layout. Can include more than one child linear or  relative layout within direct linear or relative layout of scrollView layout.

main.xml

<LinearLayout 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:orientation="vertical" >

Sunday, 23 March 2014

GridView Creation in Android Application

Simple GridView

This blog describe about display data in simple gridView.

main.xml

<LinearLayout 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:background="#7CFCff"
    android:orientation="vertical" >

Saturday, 22 March 2014

Static ExpandableListView Creation in Android App and Implementation

This blog describe about ExpandableListView creation in android apps. Through this can create more than one group including with multiple child data with each group with expand and hide list data feature.

main.xml

<LinearLayout 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:orientation="vertical" >

Saturday, 15 March 2014

Dynamic ListView Creation and Implementation Programatically in Android Application

Dynamic ListView

This blog describe about dynamic list view creation and implementation programatically in android apps. For this need to take array list and array adapter add item data list programatically . 

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_dark"
    android:orientation="vertical" >

Friday, 14 March 2014

ListView Functionality Creation and Implementation in Android Applications

Static ListView

This post describe about static ListView functionality in android applications. For list view take string array list with list items in res->values->strings.xml editor and add this list item reference with list view entries in main.xml editor.

main.xml


<LinearLayout 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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="List View"
        android:layout_marginTop="20dp"
        android:layout_gravity="center"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />

Thursday, 13 March 2014

Different Types of Layout Creation in Android Application

Linear Layout

This blog describe about different types of layout which are used in android application's user interface development. Firstly described about LinearLayout. In this blog layout orientation is "vertical" and taken TextView, EditText, Button, CheckBox and RadioButton with LayouGravity Center.

main.xml


<LinearLayout 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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Linear Layout"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:textColor="#336633"
        android:textSize="20dp"
        android:textStyle="bold"/>

Wednesday, 12 March 2014

How to Create VideoView Functionality and Implement in Android Apps


This blog describe how to create VideoView or video playing functionality in android applications with control functionality.

main.xml


<LinearLayout 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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Static Video View"
        android:textColor="#336633"
        android:textSize="20dp"
        android:textStyle="bold"
        android:layout_marginTop="20dp"
        android:layout_gravity="center" />

// No need to write manually VideoView code in xml editor drag VideiView widget from left side Palette in // graphical view of xml editor

Tuesday, 11 March 2014

Implementation of AudioMediaPlayer Functionality in Android Applications

This blog is relevant to implementation of AudioMediaPlayer functionality in android applications. To get this functionality need raw folder in Resource (res) pan pest audio file in this folder.


main.xml


<LinearLayout 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:orientation="vertical">

    <Button
        android:id="@+id/btnStart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start"
        android:layout_marginTop="20dp"
        android:layout_gravity="center"
        android:textStyle="bold"/>
  
    <Button
        android:id="@+id/btnStop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Stop"
        android:layout_gravity="center"
        android:layout_marginTop="40dp"
        android:textStyle="bold"/>
</LinearLayout>

Monday, 10 March 2014

How to Create ImageGallery and Implement in Android Apps

In this blog explain that how to create imageGallery and view gallery image individually in separate frame.


main.xml


<LinearLayout 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:orientation="vertical"
     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Gallery View"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"
        android:textColor="#339966"
        android:textSize="20sp"
        android:textStyle="bold"/>

Sunday, 9 March 2014

How to Implement DigitalClock in Android Apps

This blog explain that how to create and implement DigitalClock in android applications.


main.xml

<LinearLayout 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:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Digital Clock"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />

    <DigitalClock
        android:id="@+id/digitalClock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:textSize="20dp" />

</LinearLayout>

DigitalClockActivity.java

Saturday, 8 March 2014

How to Implement AnalogClock Functionality in Android Application

This blog explain that how to create and implement AnalogClock functionality in android application.
In xml editor no need to write code manually you have to drag from palette Date & Time column of graphical view of xml editor.


main.xml


<LinearLayout 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:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Analog Clock"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />

<!--In xml editor no need to write code manually you have to drag from palette Date & Time column of graphical view of xml editor-->

    <AnalogClock
        android:id="@+id/analogClock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
       android:background="#339966"
        android:layout_marginTop="80dp" />

</LinearLayout>

AnalogClockActivity.java

Friday, 7 March 2014

How to Create and Implement Chronometer in Android Application

In this blog you can learn how to create and implement chronometer in any android apps.To create it you have to drag Chronometer in main.xml graphical editor from palette-->Time & Date folder.
 Only there is click on start button to start chronometer functionality also can include functionality stop, restart, set format and clear format .


main.xml

<LinearLayout 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:orientation="vertical" >

  

Thursday, 6 March 2014

How to Create CalendarView Functionality in Android

In this blog you will learn how to implement CalendarView functionality in your android app.

main.xml

<LinearLayout 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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Calendar View"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />





<--- Drag CalendarView from Paletee in xml editor from Time & Date -->
  
<CalendarView
        android:id="@+id/calendarView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="40dp" />

</LinearLayout>

CalendarViewActivity.java

package com.rakesh.tiwari.calendarview;

import java.sql.Date;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CalendarView;
import android.widget.CalendarView.OnDateChangeListener;
import android.widget.Toast;

public class CalendarViewActivity extends Activity {
    CalendarView calendar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        calendar = (CalendarView) findViewById(R.id.calendarView1);
        calendar.setOnDateChangeListener(new OnDateChangeListener() {

            @Override
            public void onSelectedDayChange(CalendarView view, int year,
                    int month, int dayOfMonth) {
                // TODO Auto-generated method stub
                Toast.makeText(
                        getApplicationContext(),
                        "Selected date is :\n\n" + dayOfMonth + "-" + month
                                + "-" + year, Toast.LENGTH_LONG).show();
            }
        });
    }

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rakesh.tiwari.calendarview"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.rakesh.tiwari.calendarview.CalendarViewActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


CalendarView Functionality

CalendarView Functionality

CalendarView 

CalendarView Implementation

CalendarView Functionality

Wednesday, 5 March 2014

Android - How to Create DatePicker Functionality in Your Android App

This blog teach you how to perform DatePicker functionality and set day, month, and year.

main.xml


<LinearLayout 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:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Date Picker"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />

<--- Drag DatePicker from Paletee in xml editor from Time & Date -->

    <DatePicker
        android:id="@+id/datePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="50dp" />

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="80dp"
        android:text="Set Date"
        android:textStyle="bold" />

</LinearLayout>

DatePickerActivity.java


package com.rakesh.tiwari.datepicker;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;

public class DatePickerActivity extends Activity {
DatePicker date;
Button setdate;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
date = (DatePicker) findViewById(R.id.datePicker1);
setdate = (Button) findViewById(R.id.button1);

setdate.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(
getApplicationContext(),
"Date is :" + date.getDayOfMonth() + "-"
+ (date.getMonth() + 1) + "-" + date.getYear(),
Toast.LENGTH_LONG).show();
}
});

}

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rakesh.tiwari.datepicker"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.rakesh.tiwari.datepicker.DatePickerActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>






Tuesday, 4 March 2014

Android - How to Create TimePicker Android App

This blog will teach you how to create timePicker and set time.

main.xml

<LinearLayout 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:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="Time Picker"
        android:textColor="#336633"
        android:textSize="20sp"
        android:textStyle="bold" />

    <TimePicker
        android:id="@+id/timePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_gravity="center"
        android:layout_marginTop="50dp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="80dp"
        android:text="Set Time"
        android:textSize="20sp"
        android:textStyle="bold" />

</LinearLayout>

TimePickerActivity.java

package com.rakesh.tiwari.timepicker;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
import android.widget.Toast;

public class TimePickerActivity extends Activity {
    TimePicker tmpkr;
    Button settime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tmpkr = (TimePicker) findViewById(R.id.timePicker1);
        settime = (Button) findViewById(R.id.button1);
        tmpkr.setOnTimeChangedListener(new OnTimeChangedListener() {

            @Override
            public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(),
                        "Time is:" + hourOfDay + minute, Toast.LENGTH_LONG)
                        .show();
            }
        });

        settime.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(
                        getApplicationContext(),
                        "Time is :" + tmpkr.getCurrentHour()
                                + tmpkr.getCurrentMinute(), Toast.LENGTH_LONG)
                        .show();
            }
        });
    }

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rakesh.tiwari.timepicker"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:screenOrientation="portrait"
            android:name="com.rakesh.tiwari.timepicker.TimePickerActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


TimePicker

TimePicker Functionality

TimePicker Implementation

Monday, 3 March 2014

How to Create ImageButton Click Function in Android


In this blog you will learn how to create ImageButton and perform click and onLongClick event on imageButton through click event.

main.xml

<LinearLayout 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:orientation="vertical"
     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Image Button"
        android:textColor="#336633"
        android:textStyle="bold"
        android:layout_marginTop="40dp"
        android:textSize="20sp" />


<--- Drag ImageButton from Paletee in xml editor from Images & Media -->

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="40dp"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

ImageButtonActivity.java


package com.rakesh.tiwari.imagebutton;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

public class ImageButtonActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final ImageButton imgbtn=(ImageButton)findViewById(R.id.imageButton1);

// Perform onclick event

imgbtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

// Set different imageResource with ImageButton

imgbtn.setImageResource(R.drawable.yellowstar);

Toast.makeText(getApplicationContext(), "Image Button Clicked", Toast.LENGTH_LONG).show();
}
});

// Perform LongPress click event

imgbtn.setOnLongClickListener(new View.OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
imgbtn.setImageResource(R.drawable.greenstar);
Toast.makeText(getApplicationContext(), "Image Button Long Pressed", Toast.LENGTH_LONG).show();
return false;
}
});
}


}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.rakesh.tiwari.imagebutton"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:screenOrientation="portrait"
            android:name="com.rakesh.tiwari.imagebutton.ImageButtonActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>