Skip to main content

Posts

Simple SQLiteHelper example in android

SQLiteHelper.jar This jar has the following functions. 1. public SQLiteHelper(Context context, String dbname, CursorFactory factory, int version) This constructor is used to initialize SQLiteOpenHelper class. 2. public void createTable(String table_name, String[] fields, String[] types) This method is used to create table with fields. Total number of fields and types must be equal. 3. public ArrayList&ltHashMap&ltString, Object&gt&gt getFields(String table_name) This method will return all fields with their types as ArrayList. 4. public String insertData(String table_name, String[] fields, String[] data) This method used to insert record in our table. This will return a String as Transaction successfully completed if the transaction completed. Otherwise it will return exception. 5. public ArrayList&ltHashMap&ltString, Object&gt&gt getAllData(String table_name) This method used to get all record from our table as arraylist. 6. public Array...

Simple ListFragment Example in Android

This post will help you to create simple ListFragment in android. MainActivity.java package com.example.listfragmentexample; import android.os.Bundle; import android.app.Activity; import android.app.FragmentManager; import android.app.ListFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FragmentManager fm = getFragmentManager(); if (fm.findFragmentById(android.R.id.content) == null) { SimpleListFragment list = new SimpleListFragment(); fm.beginTransaction().add(android.R.id.content, list).commit(); } } public static class SimpleListFragment extends ListFragment { String[] numbers_text = new String[] { "one", "two", "three", "four", "five", ...

Simple Fragment Example in Android

This post will help you to create simple Fragment in android. MainActivity.java package com.simple.sfragmentexample; import android.os.Bundle; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { int i = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_simple); if (savedInstanceState == null) { Fragment newFragment = SimpleAddition.newInstance(i); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.add(R.id.FrameLayout1, newFragment).commit(); } else { i = savedInstanceState.getInt("level"); } } @Override public void onSaveIn...

Simple Fragments with Action Bar Example in Android

A Fragment represents a behavior of user interface in an Activity. A activity can have more than one fragments and also a fragment can be used in more than one activities. Screen Shots of following tutorial. Fragment 1 Fragment 2 See, Here I have used the Action Bar to navigate between tabs. Which were added in Android 3.0 (API level 11). So in lower version Action Bar doesn't work. You can take this post as Simple Action Bar tutorial in Android too :) Following class works as a home for those two Fragments. FragmentTabs.java package com.example.fragmentexample; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; public class FragmentTabs extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final ActionBar bar = getActionBar(); bar.setNavigationMode(ActionBar.N...

Change spinner text color by button click

We can change the color of spinner text by click the button. Following four steps will explain it clearly. 1. Create a xml named spinnertext.xml in res/layout folder. Here we customize the text of spinner. spinnertext.xml &ltTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/spinnerText" style="?android:attr/spinnerItemStyle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingBottom="2dp" android:paddingLeft="6dp" android:textColor="#662293" /&gt 2. Create a xml named spinner_selector.xml in res/layout folder. Here we customize the spinner drop down menu. spinner_selector.xml &ltTextView xmlns:android="http://schemas.android.com/apk/res/android" style="?android:attr/spinnerItemStyle" android:layout_width="fill_parent...

Return values from custom popup window to activity

We can return values from custom popup window to activity using listener. Example code: popup.xml &ltLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#cdcdcd" android:gravity="center" android:orientation="vertical" android:padding="50dp" &gt &ltView android:layout_width="match_parent" android:layout_height="1dp" /&gt &ltEditText android:id="@+id/bank_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:hint="Name" android:inputType="textCapWords" /&gt &ltEditText android:id="@+id/bankacc_no" android:layou...

Dialog as Toast message in Android

What is toast message?          In Adnroid, Toast is a notification message that pop up and display a cirtain amount of time. What is drawback toast message?          Toast message should displayed cirtain amount of time. We can not interrupt it within the time. For example if we set a toast message to display five seconds, we can not hide it within two or three seconds. Tha is main drawback of Toast message. How to avercome this drawback?          We can use Dialog as toast message in android. There is two main advantages by using Dialog as Toast message .         1. We can hide the Toast message any time by touching the screen.         2. While dispaly Toast message the background will goes to dim. So user can read the toast message without interruption of other views. DialogToast.java import android.app.Dialog; import android.content.Contex...