Skip to main content

Posts

PieChart using AChartEngine

AChartEngine is now the most widely used jar in the world to draw various types of following charts.             1. Graphical chart                          2. Line chart             3. Bar chart             4. Scatter chart             5. Time chart             6. Pie chart This article is about draw pie chart using achartengine. Sample screen shot of pie chart drawn using achartengine. This pie chart has the following options.         1. Movable         2. Zoomable         3. Clickable To draw this chart first you have to import achartengine  jar into your project folder. If you are using eclipse  then right click on your project --> Build Path --> Configure Build Path --...

SQLite Database Example

This is simple sqlite database tutorial without using External database. If you want to know how use external database in android then please click me! To create and access a table in android using SQLite is very simple. The following method will show how to create a table and see column names of that table in android. public void table1() { db = this.getWritableDatabase(); db.execSQL("CREATE TABLE IF NOT EXISTS table1(id INTEGER PRIMARY KEY AUTOINCREMENT , description TEXT)"); // to see colomn names in our table1 Cursor t = db.rawQuery("PRAGMA TABLE_INFO(table1)", null); if (t.moveToFirst()) { do { Log.i("", t.getString(0) + " " + t.getString(1)); } while (t.moveToNext()); } t.close(); db.close(); } And the following sample code is used to insert data into table. public void inserIntoTable1(String desc) { db = this.getWritableDatabase(); ContentValues cv = new ContentValues(); try { db.beginTrans...

SQLite Databases using External DB

This is tutorial for accessing external DB from assets folder. In android We can create sqlite database by using SQLite Database Browser. Now the question is how to access this database in source code. The answer is very simple. Store the database in assets folder that is placed in project folder. Then we can access this database in dbhelper class using context.getAssets().open(DB_NAME); After this we should copy this database to our root directory. Why because our SQLiteOpenHelper reads data from root directory only. for this we have to open new empty file in root directory by using. private String DB_PATH = "/data/data/" + context.getPackageName() + "/" + "databases/"; String DB_NAME = "database"; String outFileName = DB_PATH + DB_NAME; OutputStream myOutput = new FileOutputStream(outFileName); then we have to copy our data to this empty file by using. byte[] buffer = new byte[1024]; int length; while ((length = myInput.read...

Pie Chart in Android without using external jar

Simple Pie Chart example without using any external jar in android. Here We are creating chart using Canvas class in android. This is the sample screenshot of our application.  And this is also sample screenshot of our application. It is easy to draw this chart in android. First our xml will be. &lt?xml version="1.0" encoding="utf-8"?&gt &ltRelativeLayout 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" &gt &ltLinearLayout android:id="@+id/linear" android:layout_width="match_parent" android:layout_height="match_parent" &gt &lt/LinearLayout&gt &lt/RelativeLayout&gt Our Activity will be. public class MainActivity extends Activity { float values[] = { 70...

Multiple ArrayList in Java

Like Multiple array also we can create and use multiple arraylist. Declaration of Multiple ArrayList in JAVA. ArrayList&ltinteger&gt sets[]; initialization of Multiple ArrayList in JAVA. sets = new ArrayList[5]; Sample program using Multiple ArrayList in JAVA. public class A { static ArrayList&ltinteger&gt numbers[]; public static void main(String[] args) throws ParseException { numbers= new ArrayList[5]; numbers[0] = new ArrayList&ltinteger&gt(); numbers[0].add(1); // extending your code in order to use more than one value of the List array numbers[1] = new ArrayList&ltinteger&gt(); numbers[1].add(2); numbers[1].add(3); // if you want to get the values of first array. for(int i = 0;i&ltnumbers[1].size();i++) System.out.println(numbers[1].get(i)); // if you want to get the values of whole arraylist. for(int j = 0; j&ltsets.length;j++) for(int i = 0;i&ltnumbers[j].size();i++) System.out.println(numbers[j].get(i)); } }

Simple Timer Example in android

Here is the simple example of using timer in Android public void startTimer() { timer = new Timer(); TimerTask timerTask = new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { textView.setText(String.format(Locale.getDefault(), "%d", time)); if (time > 0) time -= 1; else { textView.setText(R.string.hello_world); btnStart.setChecked(false); } } }); } }; timer.scheduleAtFixedRate(timerTask, 0, 1000); } Full class MainActivity.java package com.guna.testapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.CompoundButton; import android.widget.TextView; import android.widget.ToggleButton; import j...

Handler in Android

This Handler will hide the textview in a few seconds later. public Handler () Since : API level 1 Default constructor associates this handler with the queue for the current thread. If there isn't one, this handler won't be able to receive messages. Define a runnable variable with your code. Runnable hide = new Runnable() { @Override public void run() { // TODO Auto-generated method stub textview.setVisibility(View.INVISIBLE); } }; public final boolean postDelayed (Runnable r, long delayMillis) Since: API Level 1 Parameters r                      The Runnable that will be executed. delayMillis      The delay (in milliseconds) until the Runnable will be executed. Returns             Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper proces...