Posts

Showing posts from 2014

Android AlertDialog Example

Giving information to the user, either to continue the process or to cancel.We can get AlertDialog through AlertDialog.Builder(Context). We can set AlertDialog title through AlertDialog.setTitle("AlertDialog Sample") and set message through AlertDialog.setMessage("Do you want to Hide/Show Button"); Full code package com.etr.alertdialogexample; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { Button hide, action; @Override protected void onCreate(Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); hide = (Button)findViewById(R.id.button1); action = (Button)findViewById(R.id.button2);

Android SharedPreferences Example

Image
A primitive data type values only stored in SharedPreferences. If stored we can use SharedPreferences values across the application. You can download source code here. Following steps:- This class used for get value from SharedPreferences and put value to SharedPreferences. package com.etr.sharedpreferenceexample; import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class PreferenceActivity extends Activity { private SharedPreferences mPref; private SharedPreferences.Editor mPrefEdit; private EditText mText; private Button mGet, mPut; @Override protected void onCreate(Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); setContentView(R.layout.activity_preference)

Android BroadCastReciever Example

When an event happens if users need intimation we can use Broadcast Receiver.Event like incoming/outgoing calls. You can download source code here . Following steps:- Add Receiver and Permission from android manifest. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.etr.broadcastreceiverexample"     android:versionCode="1"     android:versionName="1.0" >     <uses-sdk         android:minSdkVersion="8"         android:targetSdkVersion="18" />     <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />   <application             android:allowBackup="true"             android:icon="@drawable/ic_launcher"             android:label="@string/app_name"             android:theme="@style/AppTheme"

Anroid Vibrate Example

Image
We can use Vibrator as a alert to the user, for example getting incoming calls, message and Geo fence. You can download source code here. Following steps to create Android Vibrator : Add permission from Android Manifest. <uses-permission android:name="android.permission.VIBRATE"/> Next we have to create activity_vibrator.xml in that add two button one for start vibrator and another one for stop vibrator. <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="

SQLiteDatabase With Multiple Tables

Image
In the previous post,We discuss about Android SQLite Database . In this post we are going to discuss about how to create multiple tables in SQLite database.Here, We  are going to use four classes.There are, 1.SQLiteActivity 2.DatabaseHandler 3.StudentModel 4.TeacherModel SQLiteActivity :     SQLiteActivity is used to create the instance of DatabaseHandler and access its methods. DatabaseHandler :           DatabaseHandler is used to create the SQLite database and to perform CRUD operation.   StudentModel :      StudentModel contains student get() and set() method. TeacherModel :      TeacherModel contains teacher get() and set method. You can download source code here . This is code for   SQLiteActivity package com.etr.sqlitedatabasewithtwotablesexample; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Menu; public class SQLiteActivity extends Activity { DatabaseHandler mDBHandler; @Override pr

Android SQLite Database

Image
Android provides many ways to store the data.One of the way is SQLite.By default SQLite had embedded with android devices so we are no need to install it manually. SQLite is lightweight,fast,and compact.Unlike other database, SQLite need not to be configured,started,stoped,managed. Refer this post  for multiple tables in SQLite database. You can download source code here . This is code for  SQLiteActivity.I have create SQLiteHandler instance inside of SQLiteActivity and call its methods insertRecord() and getRecord(). package com.etr.sqliteexample; import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class SQLiteActivity extends Activity { EditText et_Value; Button insert_Value, get_Value; SQLiteHandler handler