Sunday, August 3, 2014

Import Export in Eclipse

Import-Export in eclipse can be used like these ways :

Import project from another workspace.
For some reason we usually have more than one workspace and each them have some project inside bur sometime we need to open a project from unopened workspace, rather than switch between workspace we can import a project from that workspace. To do this clik File in menu or just right-click in Package Explorer and click Import, import window will show up. Expand 



General and click Exsisting project into workspace and then Next, an import projects window will open and click Select root derectory (if not selected yet) then browse project folder in unopened workspace from window 



explorer and OK, it will send back to previous import project window and that chosen project folder appear in project box and already checked (check it if not), if you want to work with this project from the owner workspace (unopened workspace) directly just leave Copy project into workspace uncheck but if you want to copy it into current opened workspace check this box, by do that you will have two same project in two workspace and you can work with one of them independenly means if you do modification in one project, another same project will not updated. Finally click Finish and that project will appear in your Package Explorer.

Import Android Code from another folder.
For example we want to import sample android code from android SDK, so click Import from File menu, on import window expand Android and click 



Existing android code into workspace and then Next, an Import project window will open and browse android code from window explorer, for example : Eclipse – adt-bundle…..- Eclipse –SDK – sample - android 14 – Lunar Lander and OK. That chosen android sample code appear in project box and 



check it’s checkbox, if you want to work with this project from original place directly just leave checkbox Copy project into workspace uncheck but if you want to copy it into current opened workspace check this box, choose the second one so you can work with this code freely, you can learn it and do modification as well. Then click Finish and that code appear in your Package Explorer.

Import project from currently opened workspace.
Sometimes we need to delete some projects from Package Explorer list but not from workspace means project just disappear from list but still in workspace, this because too many project listed in Package Explorer will make eclipse take long enaugh to get ready at first time opened because eclipse will check one by one all project from error. To delete from list, right-click project name in Package Explorer – Delete – OK. Don’t check Delete project content on disk because it will delete project from workspace too. To display it back on the list click Import from File menu or right-click in Package Explorer and import window will open, expand General, click Existing project into workspace then Next. From import projects window browse the project you want to import from current workspace and click OK, it will go back to previous window and the project will appear in projects box. Notice : project sometime displayed in grey and unchecked because Copy project into workspace option still checked, just uncheck it and click Refresh to make project appear solid black and checked then click Finish and that project will be back in Package Explorer list.

Export to Archive File
Project archive file is usefull to used later to do recover project or just to compare the discrapancies between two project with same name. To archive just click Export from File menu or right-click in Package Explorer and export window will open, expand General, click Archive File then Next. In file 



system window just pick project you want to archive, you can archive the whole project or just certain folders/files to be archived. Browse the directory where the archive file will be saved, in Options you can Save in zip (recommended) or tar format, you may Compress the content of the file (recommended). Check option Create directory structure for files (recommended) if you want to archive files and complete directory structure just like in project package, or if you just want to save files and directory associated with them check Create only selected directories. Then Finish.

Export to File System
To do this click Export from File menu or right-click in Package Explorer and export window will open, expand General, click File System then Next. In file 



system window just pick project you want to save, you can save the whole project or just certain folders/files to be saved. Browse the directory where the archive file will be saved, in Options check option Create directory structure for files (recommended) if you want to archive files and complete directory structure just like in project package, or if you just want to save files and directory associated with them check Create only selected directories. Then Finish.

How to Use Archive Files / File System ?
If you for some reason lost your project, say accidentally deleted, You can import archive files use import project from another worspace procedure just like described above, just Select archive files as source.



If you want to recover some files in your project, say you make mistake that you can’t fixed, do import file system. Click Import from File menu or right-click in Package Explorer and import window will open, expand General, click File System then Next. From file system window in From directory browse file system you want to import and click OK, it will go back to previous window and the file system will appear in explorer box. Select all files in file system or pick particular files you want to import then in Into folder browse folder in your project directory (this directory must be the same with directory you pick in From directory), click Finish and just click Yes if

 
overwrite warning pop up then the failed files in your project will be recovered with file from file system. You can also use archive file to recover some failed files in your project but you have to extract it first.

Friday, August 1, 2014

Change Eclipse Editor Appearance

Default eclipse editor window use font courier new size 10 and background white, it not suit me at all because the font too small for me and the background I prefer more cool (color like green blue). May be you have same opinion with me and want to change, lets do it. I want to change the editor appearance like this :



First, open eclipse and open one project, in java editor (eg. MainActivity.java) right click and in context menu click Preferences. It will show this :



In preferences window on the left pane, expand General-Appearance-Colors and Fonts. On the right pane expand Basic and click Text Font, it will show the default font and size currently used, Click Edit to change and choose



font and size you want, for myself I choose font Lucida Console Bold size 12 and click Apply. Do it the same for Text Editor Block Selection Font. Why Lucida Console? Because just like Courier New this font is monospace font (monospace font is recomended font for programming editor) and this font distinct each character clearly like bracket () and curly bracket {} (compare to Courier New bracket () and curly bracket {}).
Next to change the background, Expand General-Editor-Text Editor, point to Appearance color options click Background color, at the right of it show




System Default checked and color box greyed, uncheck System Default and click color box to change the color then Apply, I change to color something like teal.
Now to show line number at right side of editor , point to check box above it and check Show line numbers and then Apply. If you ok with line number color that’s it but if you want to change line number color go down to Apperance color option click Line number foreground click color box and change the color, I choose black to show number more clear. So far this change will be applied to xml editor too.
These change specific to java editor, first change Static Fields to bold, to do that expand Java – Editor – Syntax coloring, at Element box expand Java




and scroll down to find Static fields and check Bold on the right of Element box and Apply.
Two more thing that I want to change are first change matching brackets highlight, in Java – Editor click Editor and in Appearance color option box click Matching brackets highlight and click color box on the right of the box, change to color yellow because I want to more bright color to make me more aware.


The second is change the way bracket highlight behave, go above Appearance color options box and in Bracket highlighting change from Matching bracket (default) to Enclosing bracket. The defference beetween two is Matching bracket just highlight one bracket only if you put cursor right on it’s couple bracket meanwhile Enclosing brackets always highlight coresponding both brackets wherever you put cursor.
To do some change in xml editor open one xml file (eg. Activity_main.xml), right click on it and choose Preferences on context menu. In Preferences window expand General – Editor – Structure Text Editor, in Appearance color options click Matching color highlight and click color box and change color to yellow.





To change attribute font to bold, expand XML – XML Files – Editor – Syntax coloring, at Syntax Element box find Attribute vakue and check Bold on the right of Syntax Element box and Apply.

That’s all guys.

Thursday, July 24, 2014

Flip ImageView Vertically and Horizontally Use Property Animation

In Android Property animation creates an animation by modifying an object's property values over a set period of time. With property animation we can animate almost any object. You can define duration, interpolation, repeat count, animation set and frame refesh time.
In this post we will animate ImageView to flip vertically and horizontally at the same time each time we tap the screen. ImageView have 3 properties that 2 of them we will use in this project ie. "rotationX" to flip vertically and "rotationY" to flip horizontally.
Now create new project and add these 2 image to drawable-mdpi folder :



In activity_main.xml declare four imageview with id: iview1,iview2,iview3,iview4, set all of them at the same place, in this project is in the center of screen and set visibility 2 of them ie. iview2 and iview4 as gone. We will flip iview1 and iview2 as a couple horizontally and iview3 and iview4 vertically.

In MainActivity.java class inside onCreate inflate xml resources above and set image resource for each of them. We create cuatom methode called flipimage. Inside this methode we will animate imageview using ObjectAnimator. This animator have four parameter that we need to fullfill, first is object, in this project is imageview (visibleimg,invisibleimg,visibleimg1,invisibleimg1) , second is name of object's property as string (rotationX, rotationY), thirth is value of from and fouth are value of to in float. In this ObjectAnimator we can set duration (ms) and set interpolator. Also use AnimationListenerAdapter to listen the end of first image animation to start the second one. Both animation (rotationX and rotationY) run at the same time for both couple imageviews. Override onTouchEvent to run flipimage methode every screen tapped.

This project need android API 11 or above and already tested with emulator.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <ImageView
        android:id="@+id/iview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>
    <ImageView
        android:id="@+id/iview2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone"/>
    <ImageView
        android:id="@+id/iview3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>
    <ImageView
        android:id="@+id/iview4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone"/>
    
</RelativeLayout>
MainActivity.java
package com.example.animation2;

import android.animation.AnimatorListenerAdapter;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;


public class MainActivity extends Activity 
{
    private ImageView iview1,iview2,iview3,iview4;
    private Interpolator accelerator = new AccelerateInterpolator();
    private Interpolator decelerator = new DecelerateInterpolator();
    private ObjectAnimator visinvis,invisvis,visinvis1,invisvis1;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //this 2 image flipped horizontally
        iview1 = (ImageView) findViewById(R.id.iview1);
        iview1.setImageResource(R.drawable.kartukid11);
        iview2 = (ImageView) findViewById(R.id.iview2);
        iview2.setImageResource(R.drawable.kartukid114);
        
      //this 2 image flipped vertically
        iview3 = (ImageView) findViewById(R.id.iview3);
        iview3.setImageResource(R.drawable.kartukid11);
        iview4 = (ImageView) findViewById(R.id.iview4);
        iview4.setImageResource(R.drawable.kartukid114);
        
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) 
    {
        //when tapped run flipimage methode
    	if (event.getAction() == MotionEvent.ACTION_DOWN) {flipimage();}
        return true;
    }
    
    private void flipimage() 
    {
    	//first image box flipped horizontally
    	final ImageView visibleimg,invisibleimg;
    	//switch visibleimg from iview1 to iview2 vice versa
    	if (iview1.getVisibility() == View.GONE) 
        {
            visibleimg = iview2;
            invisibleimg = iview1;
        } 
        else 
        {
            invisibleimg = iview2;
            visibleimg = iview1;
        }
    	//animate property rotationY of imageview (hide)use acceleratorinterpolator
        visinvis = ObjectAnimator.ofFloat(visibleimg,"rotationY", 0f, 90f);
        visinvis.setDuration(500);
        visinvis.setInterpolator(accelerator);
       //animate property rotationY of imageview (show) use deceleratorinterpolator
        invisvis = ObjectAnimator.ofFloat(invisibleimg,"rotationY",-90f, 0f);
        invisvis.setDuration(500);
        invisvis.setInterpolator(decelerator);
        //listen to end of first image animation, make it gone & 
        //start second image animation
    	visinvis.addListener(new AnimatorListenerAdapter() 
        {
            @Override
            public void onAnimationEnd(Animator anim) 
            {
                visibleimg.setVisibility(View.GONE);
                invisvis.start();
                invisibleimg.setVisibility(View.VISIBLE);
            }
        });
    	visinvis.start();
    	
    	//second image box flipped vertically
    	final ImageView visibleimg1,invisibleimg1;
    	//switch visibleimg1 from iview3 to iview4 vice versa
    	if (iview3.getVisibility() == View.GONE) 
        {
            visibleimg1 = iview4;
            invisibleimg1 = iview3;
        } 
        else 
        {
            invisibleimg1 = iview4;
            visibleimg1 = iview3;
        }
    	//animate property rotationX of imageview (hide)use acceleratorinterpolator
    	visinvis1 = ObjectAnimator.ofFloat(visibleimg1, "rotationX", 0f, 90f);
        visinvis1.setDuration(500);
        visinvis1.setInterpolator(accelerator);
        //animate property rotationX of imageview (show)use deceleratorinterpolator
        invisvis1 = ObjectAnimator.ofFloat(invisibleimg1,"rotationX",-90f, 0f);
        invisvis1.setDuration(500);
        invisvis1.setInterpolator(decelerator);
        //listen to end of first image	animation, make it gone 
        //& start second image animation
    	visinvis1.addListener(new AnimatorListenerAdapter() 
        {
            @Override
            public void onAnimationEnd(Animator anim) 
            {
                visibleimg1.setVisibility(View.GONE);
                invisvis1.start();
                invisibleimg1.setVisibility(View.VISIBLE);
            }
        });
    	visinvis1.start();
                
    }
}

Captures of emulator :

Saturday, July 19, 2014

Swap Images of Gridview Childs

This project use same custom gridview like previous post also the images. In this project we will swap or exchange 2 images of gridview childs by click two gridview childs sequencially.

In activity_main.xml, just set one gridview and set attibutes numColumn = 3 because we will make 3x3 gridview and place this gridview on top-center of the screen.In MainActivity.java, inside onCreate inflate gridview from xml. Before set adapter for gridview, make an integer array named grida with length 9, it will be used to fill gridview childs and inisialize the value with image from drawable (use image from previous project) so that all gridview child will display correspondent image. Then set adapter to gridview named ImageAdaper with two argument : Context (this) and integer array (grida). Create a new class called ImageAdapter.java that extent BaseAdapter. This adapter class is similar with Android websites example except that constructor have two parameter rather than one, they are Context and integer array. Also instantiate integer array with length 9 called gride at beginning of class. In MainActivity class, to do swap images between gridview childs when clicked set onItemClickListener to define onItemClick callback methode. In this methode at first click fill data1 with data from child clicked and at second click fill first clicked child with data from second clicked child and then fill second clicked child with data from data1 and then don’t forget to invalidateView to make gridview refresh to display latest data. Additionally to set width of gridview child use DisplayMetrics.withPixels to get screen width and then devided by three. 

This project need android API 8 or above and already tested using emulator.



 Here is the complete codes:

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"
    tools:context=".MainActivity" >

    <GridView
        android:id="@+id/gview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numColumns="3"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
    
</RelativeLayout>
MainActivity.java
package com.example.ndsc;

import android.os.Bundle;
import android.app.Activity;
import android.util.DisplayMetrics;
import import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;


public class MainActivity extends Activity 
{
	private GridView gview;
	public static int gwidth;
	private int ccounter,click1,click2,data1;
	private int[] grida =
	{
		R.drawable.kartukid11,R.drawable.kartukid11,R.drawable.kartukid11,
		R.drawable.kartukid114,R.drawable.kartukid114,R.drawable.kartukid114,
		R.drawable.kartukid119,R.drawable.kartukid119,R.drawable.kartukid119
	};
		
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//this codes to get screen width/height
		DisplayMetrics dmetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dmetrics);
		//gridview column width
		gwidth = dmetrics.widthPixels/3;
		
		gview = (GridView) findViewById(R.id.gview);
		// set custom imageadapter with 2 argument (Context,array int)
		gview.setAdapter(new ImageAdapter(this,grida));
		
		gview.setOnItemClickListener(new OnItemClickListener() 
                {
    	           @Override
    	           public void onItemClick(AdapterView<?> parent, View v,
                                                      int position, long id) 
    	           {
    		  	ccounter+=1;  //click counter
    		  	if(ccounter==1)
	    		 {
	    			 click1=position;
	    			 data1=grida[position];
	    		 }
	    		 else if(ccounter==2)
	    		 {
	    			 click2=position;
	    			 grida[click1]=grida[click2];
	    			 grida[click2] = data1;
                                 //invalidate view to refresh gridview
	    			 gview.invalidateViews();
	    			 
	    			 ccounter=0;
	    		 }
    		    }

                 });
	}
	
}
ImageAdapter.java
package com.example.ndsc;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter 
{
	private Context mcontext;
	private ImageView imageView;
	private int[] gride=new int[9]; //set gridview size 3x3
	private int gwidth = MainActivity.gwidth; //gridview column width
	
	// custom constructor with 2 parameter (Context,array int)
	public ImageAdapter(Context context, int[] gridarray)
	{
		mcontext = context;
		gride=gridarray;
	}
	
	@Override
	public int getCount() 
	{
		return gride.length;
	}

	@Override
	public Object getItem(int arg0) 
        {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0)
        {
		// TODO Auto-generated method stub
		return 0;
	}
		
	public View getView(int position, View convertView, ViewGroup parent) 
	{
	      if (convertView == null) 
	      {  
	         imageView = new ImageView(mcontext);
	         imageView.setLayoutParams(new GridView.LayoutParams(gwidth,gwidth));
	         imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
	         imageView.setPadding(3,3,3,3);
	      } 
	      else {imageView = (ImageView) convertView;}
	      //set foreground image 
	      imageView.setImageResource(gride[position]);
	      
	      return imageView;
	   }

}

Friday, July 18, 2014

Fill and Change Images of Gridview from Outside

Gridview is a viewgroup that displays items in a two-dimensional and scrollable grid. The grid items are automatically inserted to the layout using a adapter. Today we will try to fill or change images to gridview childs from outside imageview. This gridview base on Android sites example codes, we just need little modification on ImageAdapter (see codes). 
Create new android project and then put these 3 images (or use your owns) to drawable-mdpi folder. These images will be set as image resources of 3 imageview. We will fill gridview with these 3 images whichever you choose.
 

 
Lets start with activity_main.xml, in this layout set one gridview and three imageview. In gridview attibutes set numColumn = 3 because we will make 3x3 gridview and place this object on top-center of the screen. Place three imageview below this gridview.
In MainActivity.java, inside onCreate inflate gridview and three imageviews, use above three images as image resources for three imageview. Set onClickListener for all imageview to define onClick callback methode to set data1 with image resource in that clicked imageview. 
Before set adapter for gridview, make an integer array named grida with length 9, it will be used to fill gridview childs and inisialize all value with 0 (zero) means that all gridview child will be empty (no image) at first. Then set adapter to gridview named ImageAdaper with two argument : Context (this) and integer array (grida).Create a new class called ImageAdapter.java that extent BaseAdapter. This adapter class is similar with Android websites example except that constructor have two parameter rather than one, they are Context and integer array. Also instantiate integer array wih length 9 called gride at beginning of class.In MainActivity class, to display images to gridview when clicked set onItemClickListener to define onItemClick callback methode. In this methode fill integer array grida with data1 and to make gridview refresh to display latest data use invalidateView. Additionally to set width of gridview child use DisplayMetrics.withPixels to get screen width and then devided by three.

This project need android API 8 or above and already tested with emulator.

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"
    tools:context=".MainActivity" >

    <GridView
        android:id="@+id/gview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numColumns="3"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
    
    <ImageView
    	android:id="@+id/iview1"
    	android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_below="@id/gview"
        android:layout_alignParentLeft="true" />"
        
    <ImageView
    	android:id="@+id/iview2"
    	android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_below="@id/gview"
        android:layout_alignParentRight="true" />"
        
    <ImageView
    	android:id="@+id/iview3"
    	android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_below="@id/gview"
        android:layout_centerHorizontal="true" />"

</RelativeLayout>
MainActivity.java
package com.example.ndsc;

import android.os.Bundle;
import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;

public class MainActivity extends Activity 
{
	private GridView gview;
	public static int gwidth;
	private ImageView iview1,iview2,iview3;
	private int data1;
	private int[] grida ={0,0,0,0,0,0,0,0,0};
		
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//this codes to get screen width/height
		DisplayMetrics dmetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dmetrics);
		//gridview column width
		gwidth = dmetrics.widthPixels/3;
		
		gview = (GridView) findViewById(R.id.gview);
		// set custom imageadapter with 2 argument (Context,array int)
		gview.setAdapter(new ImageAdapter(this,grida));
		
		iview1= (ImageView) findViewById(R.id.iview1);
		iview1.setImageResource(R.drawable.kartukid114);
		iview1.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View view) 
			{
				data1=R.drawable.kartukid114;
			}
			
		});
		iview2= (ImageView) findViewById(R.id.iview2);
		iview2.setImageResource(R.drawable.kartukid119);
		iview2.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View view) 
			{
				data1=R.drawable.kartukid119;
			}
			
		});
		iview3= (ImageView) findViewById(R.id.iview3);
		iview3.setImageResource(R.drawable.kartukid11);
		iview3.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View view) 
			{
				data1=R.drawable.kartukid11;
			}
			
		});
		
		gview.setOnItemClickListener(new OnItemClickListener() 
                {
    	            @Override
    	            public void onItemClick(AdapterView<?> parent, View v,
                                                       int position, long id) 
    	            {
    		  	//fill gridview child with data1
    		  	grida[position]=data1;
                        //invalidate view to refresh gridview
    		  	gview.invalidateViews();
    	            }

                });
	}
	
}
ImageAdapter.java
package com.example.ndsc;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter 
{
	private Context mcontext;
	private ImageView imageView;
	private int[] gride=new int[9]; //set gridview size 3x3
	private int gwidth = MainActivity.gwidth; //gridview column width
	
	// custom constructor with 2 parameter (Context,array int)
	public ImageAdapter(Context context, int[] gridarray)
	{
		mcontext = context;
		gride=gridarray;
	}
	
	@Override
	public int getCount() 
	{
		return gride.length;
	}

	@Override
	public Object getItem(int arg0) 
        {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0)
        {
		// TODO Auto-generated method stub
		return 0;
	}
		
	public View getView(int position, View convertView, ViewGroup parent) 
	{
	      if (convertView == null) 
	      {  
	         imageView = new ImageView(mcontext);
	         imageView.setLayoutParams(new GridView.LayoutParams(gwidth,gwidth));
	         imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
	         imageView.setPadding(3,3,3,3);
	      } 
	      else {imageView = (ImageView) convertView;}
	      //set foreground image 
	      imageView.setImageResource(gride[position]);
	      
	      return imageView;
	   }

}