Android Application for HealthCare using ListView with SQLite Database


Well, after all versed applications developing for Windows Phone , lets explore mobile applications for some other resources.

Android 4 , ice cream- sandwich offers a rich set of open – source API for UI development & Open GL ES framework. Lets explore for building first an android application.

Prerequisites:

Android Toolkit:  Android API 8 or 9: 2.2 ,2,3

Android Plugin for Eclipse: https://dl-ssl.google.com/android/eclipse

Lets start by creating a new project: -> Start-> new Android Application -> Select Android ADT VM -> choose package name.

Start first building UI part:

Write in HelloWorld.java :

package com.example;

import java.util.Calendar;

import android.app.Activity;


import android.app.Activity;
import android.content.Intent;
import android.os.*;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class HelloWorldActivity extends Activity {
	
	
	
	

	
	
		
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //TextView tv = new TextView(this);
       // tv.setText("Hello,Android");
        setContentView(R.layout.main); 
       // ImageView image = (ImageView) findViewById(R.id.test_image);        
        
    //    startActivity(new Intent(this, DisplayViewsExample.class));

        
        
        Button button = (Button) findViewById(R.id.button1);
        
        button.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(HelloWorldActivity.this,WebViewExample.class);
				startActivityForResult(intent,0);
				
			}
		});
        
        Button button1 = (Button) findViewById(R.id.button3);
        
        button1.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View view) {
				// TODO Auto-generated method stub
				Intent myIntent = new Intent(HelloWorldActivity.this,Department.class);
				startActivityForResult(myIntent,0);
			}
		});
        Button button2 = (Button) findViewById(R.id.button2);
        Button button3 = (Button) findViewById(R.id.button4);
       
       
        
        
   //   startActivity(new Intent(this, Department.class));
        
    //    startActivity(new Intent(this, WebViewExample.class));

        
   
        
    }
}  

Code for Main.xml: 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1"> 
     
     <ImageButton android:id="@+id/format"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
android:onClick=""
/>
      <TextView   
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Sri Aurobindo Seva Kendra" 
         android:textStyle="bold" 
         android:textColorHighlight="#FFff00" 
         android:textSize="10pt"/>  
After home Screen development , move to next screen which is the department of hospitals. Which appears as navigation from 
one activity to another activity in Android.
Code for Department.java:

package com.example;

import android.app.Activity;
import android.widget.ScrollView;
import android.widget.LinearLayout;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;



public class Department extends Activity
{   
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //TextView tv = new TextView(this);
       // tv.setText("Hello,Android");
        ScrollView sv = new ScrollView(this);
        LinearLayout l1 = new LinearLayout(this);
        l1.setOrientation(LinearLayout.VERTICAL);
       // setContentView(R.layout.spinner); 
        sv.addView(l1); 
        
        TextView tv = new TextView(this);
        tv.setText("Departments");
         l1.addView(tv);
	
//Button button = (Button) findViewById(R.id.buttonPae);
Button button = new Button(this);
button.setText("Paediatrics");
       
 button.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(Department.this,PaediatricsDoctors.class);
				startActivityForResult(intent,0);
				
			}
		}); 
 l1.addView(button);
// Button button1 = (Button) findViewById(R.id.buttonGyn); 
 Button button1 = new Button(this);
 button1.setText("Gynaecology & Obstetrics");
 l1.addView(button1);
 
 Button button2 = new Button(this);
 button2.setText("Psychiatry");
 l1.addView(button2);
 
 Button button3 = new Button(this);
 button3.setText("General Medicine");
 l1.addView(button3);
 
 Button button4 = new Button(this);
 button4.setText("Echocardiography");
 l1.addView(button4);
 
 Button button5 = new Button(this);
 button5.setText("Eye(Opthmology)");
 l1.addView(button5);
 
 Button button6 = new Button(this);
 button6.setText("Dermatology(Skin)");
 l1.addView(button6);
 
 Button button7 = new Button(this);
 button7.setText("General Surgery");
 l1.addView(button7); 
 
 Button button8 = new Button(this);
 button8.setText("Laproscopic Surgery");
 l1.addView(button8);
 
 Button button9 = new Button(this);
 button9.setText("Dentistry");
 l1.addView(button9);
 
 Button button10 = new Button(this);
 button10.setText("Reconstructive(Plastic)");
 l1.addView(button10);
 
 Button button11 = new Button(this);
 button11.setText("ENT");
 l1.addView(button11);
 
 Button button12 = new Button(this);
 button12.setText("Gynaecological Laproscopic Surgery");
 l1.addView(button12);
 
 
 Button button13 = new Button(this);
 button13.setText("Homeopathy");
 l1.addView(button13);
 
 Button button14 = new Button(this);
 button14.setText("Gastroenterology");
 l1.addView(button14);
 
 Button button15 = new Button(this);
 button15.setText("Haemotology");
 l1.addView(button15);
 
 Button button16 = new Button(this);
 button16.setText("Audiometry & tympanometry");
 l1.addView(button16); 
 
 Button button17 = new Button(this);
 button17.setText("Neuro Surgery");
 l1.addView(button17); 
 
 Button button18 = new Button(this);
 button18.setText("Oral & Mazillofacial Surgery");
 l1.addView(button18);
 
 Button button19 = new Button(this);
 button19.setText("Cardiology");
 l1.addView(button19);
 
 Button button20 = new Button(this);
 button20.setText("Urology");
 l1.addView(button20);
 
 Button button21 = new Button(this);
 button21.setText("Neprology");
 l1.addView(button21); 
 
 Button button22 = new Button(this);
 button22.setText("Orthopaedics");
 l1.addView(button22);
 
 Button button23 = new Button(this);
 button23.setText("Oncology");
 l1.addView(button23); 
 
 Button button24 = new Button(this);
 button24.setText("Endocrino & Diabetology");
 l1.addView(button24);
 
 Button button25 = new Button(this);
 button25.setText("Acupuncture");
 l1.addView(button25);
 
 this.setContentView(sv);
	
    
	}
}
Similar build for its layout.
Next , by navigating from Button view , a stylish ListView will appear in next screen which is binded with data from SQLite 
Database. 
Code for ListView.Java:
package com.example;

import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class PaediatricsDoctors extends Activity {

private SQLiteAdapter mySQLiteAdapter;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.doctor);
      ListView listContent = (ListView)findViewById(R.id.contentlist);



      /*
       *  Create/Open a SQLite database
       *  and fill with dummy content
       *  and close it
       */
      mySQLiteAdapter = new SQLiteAdapter(this);
      mySQLiteAdapter.openToWrite();
      mySQLiteAdapter.deleteAll();

      mySQLiteAdapter.insert("Dr.(Mrs.)Bandana Hom Chowdhuri (Monday & Friday 4:30PM)");
      mySQLiteAdapter.insert("Dr.(Mrs.)D.K.Chowdhuri (Saturday 4PM)");
      mySQLiteAdapter.insert("Dr.Jaydeep Choudhury (Wednesday & Sunday 8AM)");
      mySQLiteAdapter.insert("Dr.Leena Deb (Tuesday 9AM,thursday 10AM)");
      mySQLiteAdapter.insert("Dr.Mausumi Mukherjee (Monday,Wednesday,Friday 2:30PM)");
      mySQLiteAdapter.insert("Dr.Monidipa Banerjee (Monday 9AM)");
      mySQLiteAdapter.insert("Dr.Nupur Ganguly (Thursday 8AM)");
      mySQLiteAdapter.insert("Dr.Parbati Sengupta(Monday,Wednesday 5:30PM,Thursday 6PM) ");
      mySQLiteAdapter.insert("Dr.Paromita Roy(Monday,Tuesday,Wednesday,Friday 11AM)");
      mySQLiteAdapter.insert("Dr.Radha Lakshminarayanan(Wednesday & Friday 9AM");
      mySQLiteAdapter.insert("Dr.Raja Lahiri(Tuesday & Thursday 4:30PM");
      mySQLiteAdapter.insert("Dr.Samik Basu(Wednesday 5PM)");
      mySQLiteAdapter.insert("Dr.Shaswati Saha Biswas(Tuesday 4PM)");
      mySQLiteAdapter.insert("Dr.Sudarsana De(Friday 6PM & Saturday 1:30PM)");
      mySQLiteAdapter.insert("Dr.Sudeshna Mitra(Pal)(Tuesday 7PM)");
      mySQLiteAdapter.insert("Dr.Tridib Banerjee(Wednesday 8AM)");


      mySQLiteAdapter.close();

      /*
       *  Open the same SQLite database
       *  and read all it's content.
       */
      mySQLiteAdapter = new SQLiteAdapter(this);
      mySQLiteAdapter.openToRead();

      Cursor cursor = mySQLiteAdapter.queueAll();
      startManagingCursor(cursor);

      String[] from = new String[]{SQLiteAdapter.KEY_CONTENT};
      int[] to = new int[]{R.id.text};

      SimpleCursorAdapter cursorAdapter =
       new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);

      listContent.setAdapter(cursorAdapter);

      mySQLiteAdapter.close(); 


  	}



  }
Code for SQLAdpater.java : Helper class for SQLite:

package com.example;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class SQLiteAdapter {

public static final String MYDATABASE_NAME = "MY_DATABASE";
public static final String MYDATABASE_TABLE = "MY_TABLE";
public static final int MYDATABASE_VERSION = 1;
public static final String KEY_ID = "_id";
public static final String KEY_CONTENT = "Content"; 
public static final String SUBKEY_CONTENT="SubContent";

//create table MY_DATABASE (ID integer primary key, Content text not null,SubContent text not null);
private static final String SCRIPT_CREATE_DATABASE =
"create table " + MYDATABASE_TABLE + " ("
+ KEY_ID + " integer primary key autoincrement, "
+ KEY_CONTENT + " text not null);";

private SQLiteHelper sqLiteHelper;
private SQLiteDatabase sqLiteDatabase;

private Context context;

public SQLiteAdapter(Context c){
context = c;
}

public SQLiteAdapter openToRead() throws android.database.SQLException {
sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION);
sqLiteDatabase = sqLiteHelper.getReadableDatabase();
return this;
}

public SQLiteAdapter openToWrite() throws android.database.SQLException {
sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION);
sqLiteDatabase = sqLiteHelper.getWritableDatabase();
return this;
}

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

public long insert(String content){

ContentValues contentValues = new ContentValues();
contentValues.put(KEY_CONTENT, content);
return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues);
}

public int deleteAll(){
return sqLiteDatabase.delete(MYDATABASE_TABLE, null, null);
}

public Cursor queueAll(){
String[] columns = new String[]{KEY_ID, KEY_CONTENT};
Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns,
  null, null, null, null, null);

return cursor;
}

public class SQLiteHelper extends SQLiteOpenHelper {

public SQLiteHelper(Context context, String name,
  CursorFactory factory, int version) {
 super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {
 // TODO Auto-generated method stub
 db.execSQL(SCRIPT_CREATE_DATABASE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
 // TODO Auto-generated method stub

}

}

}
Lets enjoy Android Application development. After running the application explore the various screen shots. 

This slideshow requires JavaScript.

 

Advertisements

About Anindita
Anindita Basak is working as Big Data Cloud Consultant in Microsoft. Worked in multiple MNCs as Developer & Senior Developer on Microsoft Azure, Data Platform, IoT & BI , Data Visualization, Data warehousing & ETL & of course in Hadoop platform.She played both as FTE & v- employee in Azure platform teams of Microsoft.Passionate about .NET , Java, Python & Data Science. She is also an active Big Data & Cloud Trainer & would love share her experience in IT Training Industry. She is an author, forum contributor, blogger & technical reviewer of various books on Big Data Hadoop, HDInsight, IoT & Data Science, SQL Server PDW & PowerBI.

2 Responses to Android Application for HealthCare using ListView with SQLite Database

  1. Pingback: Prestashop Templates

  2. xpectree says:

    Very nice app, how can i put buttons in my listview (i’m using SQlite) to go for example, to the details of a course, and other button to see a video taken the info of the sqlite for the element selected, thanks a lot!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: