Friday, 25 May 2012

Data Base Application(add,view,update,delete)

 DatabaseapplicationActivity.java


package com.databaseapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class DatabaseapplicationActivity extends Activity {
    /** Called when the activity is first created. */
    EditText name,age,qual,place;
    String name1,age1,qual1,place1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
       
        name=(EditText)findViewById(R.id.editText1);
        age=(EditText)findViewById(R.id.editText2);
        qual=(EditText)findViewById(R.id.editText3);
        place=(EditText)findViewById(R.id.editText4); 
     
       
    }
    public void submit(View v)
    {
        name1=name.getText().toString();
        age1=age.getText().toString();
        qual1=qual.getText().toString();
        place1=place.getText().toString();
        details d=new details();
        d.setName(name1);
        d.setAge(age1);
        d.setQual(qual1);
        d.setPlace(place1);
       
       
        databasehandler dbh=new databasehandler(this);
        dbh.insert(d);
        Toast.makeText(getApplicationContext(),"Details Submitted Successfully", Toast.LENGTH_LONG).show();
    }
    public void viewDetails(View v)
    {
        Intent i=new Intent(this,second.class);
        startActivity(i);
    }
   
public void editDetails(View v)
{
Intent k=new Intent(this,third.class);
startActivity(k);
}
public void deletedata(View v)
{
    Intent l=new Intent(this,fourth.class);
    startActivity(l);
}
}




Database Handler


package com.databaseapp;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

public class databasehandler  extends SQLiteOpenHelper{
   
    private static final String MYDB="mydb";
    private static final String MYTB="USER";
    public String deleted;
    SQLiteDatabase db;
    Context context;
   
    public databasehandler(Context context) {
        super(context,MYDB, null, 32);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("create table if not exists "+MYTB+" (id integer primary key autoincrement,name text,age text,qualification text,place text)");
        //db.close();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("drop table if exists "+MYTB);
        onCreate(db);
    }
public void insert(details d) {
    Log.v("Errror","here");
    SQLiteDatabase db=getWritableDatabase();
   
    ContentValues cv=new ContentValues();
    cv.put("name",d.getName());
    Log.v("name",d.getName());
    cv.put("age",d.getAge());
    Log.v("age",d.getAge());
    cv.put("qualification",d.getQual());
    Log.v("qualification",d.getQual());
    cv.put("place",d.getPlace());
    Log.v("place",d.getPlace());
   
    db.insert(MYTB,"id",cv);
    Log.v("data","inserted");
}

public ArrayList<String> resultdata() {
    ArrayList<String> results=new ArrayList<String>();
    SQLiteDatabase db = this.getReadableDatabase();
    try {   
        Cursor c=null;
         c = db.rawQuery("select * from "+MYTB, null);
       
        if (c!= null) {
        Log.v("cursor","notnull");
            if (c.moveToFirst());
            {
            do {
                    int cc=c.getCount();
                    Log.v("cursor count",""+cc);
                   
                    String Name = c.getString(c.getColumnIndex("name"));
                    Log.v("Name",Name);

                    String Age = c.getString(c.getColumnIndex("age"));
                    Log.v("Age",Age);
                   
                    String Qualification=c.getString(c.getColumnIndex("qualification"));
                    Log.v("Qualification",Qualification);
                   
                    String Place=c.getString(c.getColumnIndex("place"));
                    Log.v("Place",Place);
                   
                    String id=c.getString(c.getColumnIndex("id"));
                    Log.v("id",id);
                   
                    results.add( "\n Id: "+id+"\n Name: " +Name+"\n Age : " +Age+"\n Qualification : "+Qualification+"\n Place :"+Place);
                    //results.add("dfrty");
                    Log.v("Array",""+results);
                }
            while (c.moveToNext());
            }}
        else
        {
            Toast.makeText(context, "results empty",Toast.LENGTH_LONG).show();
            results.equals(null);
        }
    } catch (SQLiteException se) {
        Log.e(getClass().getSimpleName(),
                "Could not create or Open the database");
    }
    return results;
}


public Cursor update(String i){
    Cursor c;
    SQLiteDatabase db=this.getWritableDatabase();
    String[] columns={"name","age","qualification","place"};
    String selection="id=?";
    String[] selectionArgs={i};
    Log.v("selection",selection);
    Log.v("selectionargs",i);
    c=db.query(MYTB, columns, selection, selectionArgs, null, null, null);
    //db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy)
    return c;
   
   
}
public void updateDetails(details d,String id1) {
    //db.close();
    Log.v("db","notclosed");
    db=getWritableDatabase();
   
    ContentValues cv=new ContentValues();
    Log.v("update","query");
    cv.put("name",d.getName());
    Log.v("name",d.getName());
    cv.put("age",d.getAge());
    Log.v("age",d.getAge());
    cv.put("qualification",d.getQual());
    Log.v("qualification",d.getQual());
    cv.put("place",d.getPlace());
    Log.v("place",d.getPlace());
    String where="id=?";
    String [] whereArgs={id1};
    db.update(MYTB, cv, where,whereArgs);

}

public void deletedetails(String idd)
{
    Cursor c=null;
    Log.v("ivalue", ""+idd);
    SQLiteDatabase db=getWritableDatabase();
    deleted="false";
    String[] columns={"name","age","qualification","place"};
    String selection="id=?";
    String[] selectionArgs={idd};
    Log.v("selection",selection);
    Log.v("selectionargs",idd);
    c=db.query(MYTB, columns, selection, selectionArgs, null, null, null);
    //db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy)
    if(c!=null)
    {
        if( c.moveToFirst())
        {
            String where="id=?";
            String[] args={idd};
            Log.v("value",""+args);
            db.delete(MYTB, where, args);
            deleted="true";
                   
        }
        else
        {
            deleted="false";
        }
       
    }
    else
    {
        deleted="false";
    }
   
}

}
   
get and set
package com.databaseapp;

public class details {
    String name,age,qual,place;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getQual() {
        return qual;
    }

    public void setQual(String qual) {
        this.qual = qual;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

}
Listview
package com.databaseapp;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class second extends Activity {
   
ListView list;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
        list=(ListView)findViewById(R.id.listView1);

        databasehandler dbh=new databasehandler(getApplicationContext());
       
        ArrayList<String > result=new ArrayList<String>();
        result=dbh.resultdata();
        Log.v("reached",""+result);
       
        if (result.isEmpty()==true)
        //Log.v("after clear",""+result);
       
        {
            Toast.makeText(getApplicationContext(),"Database empty",Toast.LENGTH_LONG).show();
           
        }
        else
        {
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, result);
            list.setAdapter(adapter);
        }

}
}
update
package com.databaseapp;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class third  extends Activity{
    EditText t1,t2,t3,t4,t5;
    String name1,age1,qual1,place1,id1;
    SQLiteDatabase db;
    @Override
   
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.third);
        t1=(EditText)findViewById(R.id.id1);
        t2=(EditText)findViewById(R.id.txt1);
        t3=(EditText)findViewById(R.id.txt2);
        t4=(EditText)findViewById(R.id.txt3);
        t5=(EditText)findViewById(R.id.txt4);
    }
    public void editdetails(View v)
    {
        String id1=t1.getText().toString();
        databasehandler dbh=new databasehandler(this);
       
        Cursor c=null;
         c=dbh.update(id1);
       
        if(c!=null)
        {
            Log.v("db","null");
           
            Log.v("inside","cursor");
            if( c.moveToFirst())
            {
            String s=c.getString(c.getColumnIndex("name"));
            Log.v("name",s);
            String p=c.getString(c.getColumnIndex("age"));
            String q=c.getString(c.getColumnIndex("qualification"));
            String r=c.getString(c.getColumnIndex("place"));
            t2.setText(s);
            t3.setText(p);
            t4.setText(q);
            t5.setText(r);
            c.close();
            // dbh.db.close();
           
        }
        else
        {
            Toast.makeText(getApplicationContext(), "no data found", Toast.LENGTH_LONG).show();
        }
        }
        else
        {
            Toast.makeText(getApplicationContext(), "No data found", Toast.LENGTH_LONG).show();
        }   
    //db.close();   
    }
    public void updatedata(View v)
    {
        Log.v("ivide","ethi");
        databasehandler dbh=new databasehandler(this);
        name1=t2.getText().toString();
        Log.v("updatedname",name1);
        age1=t3.getText().toString();
        Log.v("updateage",age1);
        qual1=t4.getText().toString();
        Log.v("updatedqual",qual1);
        place1=t5.getText().toString();
        Log.v("updatedplace",place1);
        id1=t1.getText().toString();
        details d=new details();
        d.setName(name1);
        d.setAge(age1);
        d.setQual(qual1);
        d.setPlace(place1);
        Log.v("going to","update query");
        dbh.updateDetails(d,id1);
        Toast.makeText(getApplicationContext(),"Updated",Toast.LENGTH_LONG).show();
    }
    public void viewdata1(View v)
    {
        Intent i =new Intent(third.this,second.class);
        startActivity(i);
    }
}
delete
package com.databaseapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class fourth extends Activity{
    EditText t1;
    @Override
   
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fourth);
        t1=(EditText)findViewById(R.id.etxt1);
    }
    public void deleteDetails(View v)   
    {
        String idd=t1.getText().toString();
        databasehandler dbh=new databasehandler(this);
        dbh.deletedetails(idd);
        String s=dbh.deleted;
        if( s=="true")
        {
        Toast.makeText(getApplicationContext(), "deleted", Toast.LENGTH_LONG).show();
        }
        else
        {
            Toast.makeText(getApplicationContext(), "no data found", Toast.LENGTH_LONG).show();
        }
    }
   

}




Thursday, 24 May 2012

JSON Parsing

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class PhpSqlSampleActivity extends Activity {
    InputStream is;
    String result = "";
    String data = "";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    public void click(View v)
    {
        EditText et=(EditText)findViewById(R.id.et1);
        String name=et.getText().toString();
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("student",name));
        
        //http post
        try{
                HttpClient httpclient = new DefaultHttpClient();

 //should specify the suitable http path.

                HttpPost httppost = new HttpPost("http://10.0.0.200/text/select.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
        }catch(Exception e){
                Log.e("log_tag", "Error in http connection "+e.toString());
        }
       
        //convert response to string
        try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                }
                is.close();
          
                result=sb.toString();
        }catch(Exception e){
                Log.e("log_tag", "Error converting result "+e.toString());
        }
        
        //parse json data
        try{
     
           
           
              JSONArray jArray = new JSONArray(result);
               
                for(int i=0;i<jArray.length();i++){
                        JSONObject json_data = jArray.getJSONObject(i);
                        int id=json_data.getInt("id");
                        String std=json_data.getString("name");
                        String place=json_data.getString("place");
                        int rank=json_data.getInt("rank");
                        data="Student Id = "+id+"\n"+"Student name = "
                        +std+"\n"+"Place = "+place+"\n"+"Rank = "+rank;
                       
                      
                        Log.i("log_tag",data);
                       
                }
        }
       
        catch(JSONException e)
        {
                Log.e("log_tag", "Error parsing data "+e.toString());
        }
        new AlertDialog.Builder(this).setPositiveButton("Ok",new OnClickListener() {

            //@Override
            public void onClick(DialogInterface dialog, int which)
            {

            }
    }).setMessage(data).setTitle("Student Details").create().show();
    }
}

This application is used to get the details of the student while we entering the name of the student in to the edit text box.

In ubuntu the php files should be in file system->opt->lampp->htdocs->anna(folder name)

Here giving some examples of the .php files

  •  if you want to select the data from the 'department table'.

<?php
    mysql_connect("localhost","root","");
mysql_select_db("studentnew");

$q=mysql_query("SELECT * FROM department");
while($e=mysql_fetch_assoc($q))
        $output[]=$e;

print(json_encode($output));

mysql_close();
?>

  • if you want we want to get the student data from the student table according to the name of the student.

 <?php
    mysql_connect("localhost","root","");
mysql_select_db("studentnew");

$q=mysql_query("SELECT * FROM studentdata WHERE id='".$_REQUEST['student']."'");
while($e=mysql_fetch_assoc($q))
        $output[]=$e;

print(json_encode($output));

mysql_close();
?>

  •  if we want to insert data in to the table

<?php
    mysql_connect("localhost","root","");
mysql_select_db("studentnew");

$q=mysql_query("INSERT INTO staffreg (name,id,department,gender)
VALUES ('".$_REQUEST['sname']."','".$_REQUEST['sid']."','".$_REQUEST['sdep']."','".$_REQUEST['srm']."')");
while($e=mysql_fetch_assoc($q))
        $output[]=$e;

print(json_encode($output));

mysql_close();
?>

Log in page

package com.ann;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class studentLogin extends Activity{
    EditText ename,epass;
    Button bsave;
    TextView txt;
    String name,pass,result;
    InputStream is;
    String nname;
   
   
   
    public void onCreate(Bundle saveInstanceState)
    {
        super.onCreate(saveInstanceState);
        setContentView(R.layout.studentlogin);
        ename=(EditText)findViewById(R.id.stnee);
    epass=(EditText)findViewById(R.id.stpee);
   
    }
    public void onclickLoginss(View v){

        bsave=(Button)findViewById(R.id.buts);
        name=ename.getText().toString();
        pass=epass.getText().toString();
                try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://10.0.0.210/anna/stul.php");
           // httppost.setEntity(new UrlEncodedFormEntity(nameval));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
    }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
    }
       
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
            }
            is.close();
      
            result=sb.toString();
            Log.e("result", ""+result);
    }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
    }
    
    //parse json data
    try{      
          JSONArray jArray = new JSONArray(result);
           
            for(int i=0;i<jArray.length();i++){
                    JSONObject json_data = jArray.getJSONObject(i);
                   
                   String nameva=json_data.getString("name");
                   String passva=json_data.getString("id");
                  
                    
//            }
            if(name.equalsIgnoreCase(nameva) && (pass.equalsIgnoreCase(passva)))
            {
                Intent intent=new Intent(this,studentPage.class);
                intent.putExtra("name", nameva);
                startActivity(intent);
                //break;
                //Toast.makeText(this,"name  :"+nameva+"   password:"+passva, Toast.LENGTH_LONG).show();
            }
            else {
                Toast.makeText(this,"user name or password is not correct",Toast.LENGTH_LONG).show();
                ename.setText("");
                epass.setText("");
                break;
            }
            }        
   
    }
    catch(Exception e){
        Log.e("error",""+e.getMessage());
    }
   
   
    }
      

}



Registration form

 

 


package com.ann;

import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class studentReg extends Activity {
   
    EditText ename,edep;
    EditText eid;
    RadioButton rma,rfe;
    String sname,sid,sdep,srm,srf;
    int id;
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.studentreg);
       
        ename=(EditText)findViewById(R.id.sne);
        eid=(EditText)findViewById(R.id.side);
        edep=(EditText)findViewById(R.id.sde);
        rma=(RadioButton)findViewById(R.id.male);
        rfe=(RadioButton)findViewById(R.id.female);
       
       
       

    }
    public void onClickSave(View v){
        sname=ename.getText().toString();
        sid=eid.getText().toString();
        sdep=edep.getText().toString();
        if(rma.isChecked()==true){
        srm="male";   
        }
        else if(rfe.isChecked()==true){
            srm="female";
       
        }
        ArrayList<NameValuePair> nameval=new ArrayList<NameValuePair>();
        nameval.add(new BasicNameValuePair("sname", sname));
        nameval.add(new BasicNameValuePair("sid", sid));
        nameval.add(new BasicNameValuePair("sdep", sdep));
        nameval.add(new BasicNameValuePair("srm", srm));
       
        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://10.0.0.210/anna/studentregnew.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameval));
            HttpResponse response = httpclient.execute(httppost);

        Toast.makeText(this,"id"+sid+"name:"+sname+"dep:"+sdep+"gen:"+srm, Toast.LENGTH_LONG).show();

        ename.setText("");
        eid.setText("");
        edep.setText("");
    }catch (Exception e){
                 Log.e("log_tag", "Error in http connection "+e.toString());
         }
    }
   
    public void onClickHome(View v){
        Intent i=new Intent(this,home.class);
        startActivity(i);
               
    }

}



Thursday, 17 May 2012

Exit from one Application

public void exit(View v){
        Intent i=new Intent(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_HOME);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);
    }

Monday, 14 May 2012

ImageGallery

package com.ann;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Toast;

public class ImageGalleryExpActivity extends Activity {
    TextView myselection;
    Gallery mygallery;
    ImageView img;
    public int[] myImageIds = { R.drawable.apple,R.drawable.baby,
               R.drawable.candle, R.drawable.flower,R.drawable.cat,R.drawable.images };
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myselection =(TextView)findViewById(R.id.textView1);
        img=(ImageView)findViewById(R.id.imageView1);
       
        // Bind the gallery defined in the main.xml
        // Apply a new (customized) ImageAdapter to it.

        mygallery = (Gallery) findViewById(R.id.gallery1);

        mygallery.setAdapter(new ImageAdapter(this));
        //ImageAdapter imga;
       
       
            mygallery.setOnItemSelectedListener(new OnItemSelectedListener() {

                public void onItemSelected(AdapterView<?> parent, View v,
                        int position, long id) {
                    int pos=position+1;
                    switch (pos) {
                    case 1:
                    {
                        myselection.setText(" selected image is Apple" );
                    }
                        break;
                    case 2:
                    {
                        myselection.setText(" selected image is Baby" );
                    }
                        break;
                    case 3:
                    {
                        myselection.setText(" selected image is candle" );
                    }
                        break;
                    case 4:
                    {
                        myselection.setText(" selected image is Flower" );
                    }
                        break;
                    case 5:
                    {
                        myselection.setText(" selected image is Cat" );
                    }
                        break;
                       
                    case 6:
                    {
                        myselection.setText(" selected image is Rose");
                    }
                        break;
                       
                    default:
                        break;
                    }
                   
                   
                   
                    Toast.makeText(ImageGalleryExpActivity.this,"selected image is at position  "+pos,Toast.LENGTH_LONG).show();
               
                //img.setImageResource(myImageIds[position]);
                   
                }

                public void onNothingSelected(AdapterView<?> parent) {
                    myselection.setText("Nothing selected");
                   
                }


            });
        }
        public class ImageAdapter extends BaseAdapter {
            /** The parent context */
            private Context myContext;
           
            /** Simple Constructor saving the 'parent' context. */
            public ImageAdapter(Context c) {
                this.myContext = c;
            }
            // inherited abstract methods - must be implemented
            // Returns count of images, and individual IDs
            public int getCount() {
                return myImageIds.length;
            }

            public Object getItem(int position) {
                return position;
            }

            public long getItemId(int position) {
                return position;
            }
            // Returns a new ImageView to be displayed,
            public View getView(int position, View convertView,
                    ViewGroup parent) {

                // Get a View to display image data                    
                ImageView iv = new ImageView(this.myContext);
                iv.setImageResource(myImageIds[position]);

           
      // Set the Width & Height of the individual images
        iv.setLayoutParams(new Gallery.LayoutParams(150,100));

                return iv;
            }}
       
}