Pages

Thursday, 17 October 2013

Get the Android SDK

The Android SDK provides you the API libraries and developer tools necessary to build, test, and debug apps for Android.
If you're a new Android developer, we recommend you download the ADT Bundle to quickly start developing apps. It includes the essential Android SDK components and a version of the Eclipse IDE with built-in ADT (Android Developer Tools) to streamline your Android app development.
With a single download, the ADT Bundle includes everything you need to begin developing apps:
  • Eclipse + ADT plugin
  • Android SDK Tools
  • Android Platform-tools
  • The latest Android platform
  • The latest Android system image for the emulator
  • Click Here

Wednesday, 16 October 2013

Insert,Update,Delete in Android with Sqlite

MainActivity.java

package com.example.dml;
 import java.util.Locale;
 import android.app.Activity;
 import android.content.ContentValues;
 import android.content.Intent;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.Bundle;
import android.view.View;
 import android.widget.Button;
 import android.widget.Toast;
 public class MainActivity extends Activity {
private SQLiteDatabase db;
 Button up;
 private String table_name="StudentInfo";
private String database_name="Test.db";
 private Object Button;
public static final String KEY_ROWID = "sid";
 public static final String KEY_NAME = "name";
public static final String KEY_AGE = "age";
 public static final String KEY_COURSE = "course";
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
 db = openOrCreateDatabase(database_name , SQLiteDatabase.CREATE_IF_NECESSARY, null);
 db.setVersion(1);
 db.setLocale(Locale.getDefault());
 db.setLockingEnabled(true);
// creating table in database
db.execSQL("CREATE TABLE IF NOT EXISTS "+table_name+" " + "( sid INTEGER PRIMARY KEY AUTOINCREMENT," + " name TEXT," + " age INTEGER," + " course TEXT ); ");
 }
public void onClick(View v) {
switch(v.getId()) {
 case R.id.btnInsert
: Insert("Rohit", "19", "BBA");
break;
 case R.id.btnUpdat:
 Update(1, "Rohit", "20", "BCA");
 break;
 case R.id.btnDelete:
Delete(1);
break;
} }
 public void Insert(String name, String age, String course)
{
 ContentValues data=createContentValues(name, age, course);
 db.insert(table_name, null, data);
 Toast.makeText(this, "Record Inserted", Toast.LENGTH_SHORT).show();
 }
// updating record in the database
 public void Update(int sid, String name, String age, String course)
 {
ContentValues updateValues = createContentValues(name, age, course);
db.update(table_name, updateValues, KEY_ROWID+"="+sid, null);
 Toast.makeText(this, "Record Updated", Toast.LENGTH_SHORT).show();
 }
// deleting record rom the database
public void Delete(int sid)
{
 db.delete(table_name, KEY_ROWID+"="+sid, null);
 Toast.makeText(this, "Record Deleted", Toast.LENGTH_SHORT).show();
 }
// return a content of the database
 private ContentValues createContentValues(String name, String age, String course)
{
ContentValues values = new ContentValues();
values.put(KEY_NAME, name);
 values.put(KEY_AGE, age);
 values.put(KEY_COURSE, course);
 return values;
 } }


activity_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=".MainActivity" >

 <Button android:id="@+id/btnInsert"

              android:text="Insert"

              android:layout_width="wrap_content"

              android:layout_height="wrap_content"

              android:onClick="onClick"/>
 <Button
        android:id="@+id/btnDelete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btnInsert"
        android:layout_below="@+id/btnInsert"
        android:layout_marginLeft="24dp"
        android:layout_marginTop="107dp"
        android:onClick="onClick"
        android:text="Delete" />


 <Button
        android:id="@+id/btnUpdate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnInsert"
        android:layout_marginLeft="57dp"
        android:layout_toRightOf="@+id/btnDelete"
        android:onClick=""
        android:text="Update" />

</RelativeLayout>







Tuesday, 15 October 2013

Android Sqlite Tutorial

SQLite is a relational database management system (RDBMS). What makes SQLite unique is that it is considered an embedded solution. Most database management system such as Oracle, MySQL, and SQL Server are standalone server processes that run independently.
SQLite is actually a library that is linked into applications. All database operations are handled within the application through calls and functions contained in the SQLite library. This is great news while you’re learning to use SQLite because it makes it much easier to manipulate even large databases when compared to more conventional database solutions.
In case you’re interested, SQLite is actually written in C and contained within a Java-based “wrapper” provided by the Android SDK.
SQLite does rely on Structured Query Language (SQL); the same language used by most other RDBMSs. If you’re already familiar with SQL from another database system, you have a serious head start using SQLite because you will find that most query commands are structured exactly the same way.