Search This Blog

Monday, 23 July 2012

Replacing spinner with drop down alert in android application

Dialog box are powerful tools in android. They have given so much access in dialog box so that we  do not need to use spinner. You can create simple Alert Dialog, Custom Alert dialog, Multiple choice, Single choice , Alert Dialog with Base adapter. We easily can create them.

I am going to create All type of dialog boxes with screen shot and source code.

1) Simple Alert Box or Default Alert Box - creating a simple alert dialog is very simple

   private void SimpleAlert() {  
     Builder builder = new AlertDialog.Builder(this);  
     builder.setTitle("Simple Alert");  
     builder.setMessage("This is simple alert box");  
     builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {  
       @Override  
       public void onClick(DialogInterface dialog, int which) {  
         dialog.dismiss();  
       }  
     });  
     AlertDialog alert = builder.create();  
     alert.show();  
   }  


Saturday, 7 July 2012

Android mobile game development part III : drawing and moving image on android surface view

Now we come closer to be able to make a simple 2D game in android. Before you start this new article which include

1) Create one canvas to draw bitmap or images on android surface view

2) Create dynamically unlimited images and move them on surface

Please see previous article to get more idea

Coordinate system in mobile gaming and creating some simple figure Like Square and Handle Touch event in android canvas 

I have created same thing in two ways First using Surface View and View.First make one User Interface to select an option , how you want to draw?  you can see the difference between performance by increasing number of images. So take one activity and make view like this.You need not worry as i posted full source code at the end


Now  we will need two separate class one to draw in SurfaceView and another using view.
Here we go with surface view and simple draw some bitmap inside canvas . I have taken one ArrauList to save information of coordinate where bitmap need to be draw that are created when you touch the surface.

    private Vector<Integer> xCoordinate = new Vector<Integer>();
    private Vector<Integer> yCoordinate = new Vector<Integer>();
    private ArrayList<Integer> speed = new ArrayList<Integer>();

speed array is to decide of bitmap. here is code to draw bitmap
Android News and source code