Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

Monday, 9 March 2015

Android Apps Development Training

Android apps development training for the month of May 2015 is now open for registration. Seats are limited. The training is as follows:-

Date: 26 - 27 May 2015 (2 days)
Venue: Armada Hotel, Petaling Jaya, Selangor, MALAYSIA

For more info, contact 03-777 31631 or fill up the registration form here.

Aimed for beginners, this android training program is based on hands-on and step-by-step approach. Basic programming knowledge is an advantage.

Visit Innovacia Mobile for more info.


Tuesday, 17 July 2012

Android Tutorial: KeyEvent

This tutorial will show you how to handle when a user press the Back key.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        // IF CLICK BACK BUTTON
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            //INSTRUCT WHAT HAPPEN HERE
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


Tuesday, 5 April 2011

Android ListView Example

This is another tutorial on android application development. It's about ListView where you have several options or list of options for the users to view or select.

We'll show you how:-
1. to create the ListView
2. to add items into the ListView
3. to pop up the item chosen by the user

Step 1
Go to res/layout and open up the main.xml file. Add the following code:-

<ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>

Step 2
Go to src folder and open up your .java file. Add the following code:-

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;


public class activityTestListView extends Activity 
{
    private ListView lv1;
    private String lv_arr[]={"Option 1","Option 2","Option 3"};
         
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
   {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        lv1=(ListView)findViewById(R.id.ListView01);
        lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));
        lv1.setTextFilterEnabled(true);
        

        //this line is what will happen when user click on the item
        lv1.setOnItemClickListener(new OnItemClickListener()
         {
        @Override
         public void onItemClick(AdapterView<?> a, View v, int position, long id)
            {
            AlertDialog.Builder adb=new AlertDialog.Builder(activityListView.this);
            adb.setTitle("LVSelectedItemExample");
            adb.setMessage("Selected Item is = "+lv1.getItemAtPosition(position));
            adb.setPositiveButton("Ok", null);
            adb.show();
            }
         });

    }
}

Note:-
~ replace "Option 1", "Option 2" and "Option 3" with your own preference

Run the project and click on any item from the listing.

Roger,
mytikus

Making Simple Toast Notification

We use toast notification quite often, especially during testing. Toast notification is a pop up window to show certain message to the users. Toast notification does not involve user interaction (there is no OK, Cancel, Yes, No etc). It will automatically fade in and out. See the sample code below:-

In .java file, put the following code:-

import android.widget.Toast;

public class activityTestToast extends Activity 
{  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
   {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //this line will pop up the message when the application is created
        Toast.makeText(this, "Cikucak!!", Toast.LENGTH_SHORT).show();

   }
}

NOTE:-
1. Replace the work "Cikucak" with any message you prefer.
2. Try LENGTH_SHORT or LENGTH_LONG and see the difference

It's quite simple, right?

Monday, 4 April 2011

Playing Audio File from Raw Resources

We'll share some info on how to play audio or video which can be stored in application's resource folder (res > raw).


Step 1: Put the audio/video file in (res/raw) folder of your project. If the "raw" folder does not exist, create one.
Step 2: Put in the following code:-


Private MediaPlayer mp;

mp = MediaPlayer.create(this, R.raw.audiofilename);
                    mp.setLooping(true);
                    mp.start();

Note:-
1. Change the audiofilename according to your own audio file name.
2. When you mp.setLooping(true), the audio file will play continuosly until you stop it.

Roger,
mytikus

How to Use Button Click

Button is the most commonly use function to fire up an event or action. We'll show an example to use button with android. How to get an action when you click on a button?


In your main.xml file, create the button like this:-
<Button android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="myClickHandler" 
    android:text="Click Me"/>


Then in your .java file, put this code:-

public class buttonclick extends Activity
{
    private Button btnclickme;    

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnclickme = (Button) findViewById(R.id.Button01);

        btnclickme.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)            
            {
                 //what happen when click            
                 //put your code here
             }
         });               
    }
}



How's that? Hope that's helpful.

Radio Button and Radio Group

You use radio button to allow users to select certain item from several options. What if you want to allow user to select only one item? You can use Radio Group.

In the layout folder, open the main.xml file and put in the following code:-

<RadioGroup android:layout_width="fill_parent"
android:layout_height="fill_parent"
 android:orientation="vertical"
 android:id="@+id/QueGroup1">

            <RadioButton android:text=" Option 1..........."
            android:textColor="#ffff00"
             android:id="@+id/RadioButton01"
             android:layout_width="wrap_content"
             android:checked="true"
             android:layout_height="wrap_content">
             </RadioButton>
            
             <RadioButton android:text=" Option 2.........."
             android:textColor="#ffff00"
             android:id="@+id/RadioButton02"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"></RadioButton>
</RadioGroup>

User can only select one item (either Option 1 OR option 2) from the Radio Group. Hope that will help.


Roger,
~mytikus