Powered By Blogger

Tuesday 20 March 2012

Spinner with databse

How to populate a Spinner widget from a database


 Yesterday we saw how to populate a Spinner widget from an Array, and today, as promised, I'll show you how to populate a Spinner widget from a database.

 This tutorial assumes that you're using the same code we used previously (link above), essentially the only differences are that we're using a different type of Adapter (a SimpleCursorAdapter this time) and populating it with the results of a query from a database table, and we're using a separate layout item to put our colour names


 Here is our new layout, called db_view_row.xml:

<LinearLayout android:id="@+id/LinearLayout01"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android">

 <TextView android:text=""
 android:id="@+id/tvDBViewRow"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content">
 </TextView>
 </LinearLayout>

 put this file in your res/layout directory in your project.


 Let's assume for this example that you've already populated your database table with the same list of colours that we used previously.

 Here's the statement to create our table structure:


 CREATE TABLE "colours" (
 "_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
 "colourName" TEXT NOT NULL
 )



 In our database adapter class we have a method called fetchAllColours(), which has the responsibility (probably no surprises here) of fetching all our colours ;).


 At the top of our class we declare some static variables we're going to use :


 public class TestDBAdapter {

 public static final String KEY_TITLE = "colourName";
 public static final String KEY_ROWID = "_id";

 //..rest of class continues from here..


 Here is this method also from our TestDBAdapter class:

 public Cursor fetchAllColours()
 {
 if (mDb == null)
 {
 this.open();
 }

/* here we check if our db exists as the connection might have been closed unexpectedly... and open it if it doesn't already exist*/


 String tableName = "colours";

 return mDb.query(tableName, new String[] { KEY_ROWID, KEY_TITLE}, null, null, null, null, null);

 }


 ... which returns a database Cursor to our method below..


 private void fillData() {
 Cursor coloursCursor;
 Spinner colourSpinner = (Spinner) findViewById(R.id.my_colour_spinner);
coloursCursor = thisTestDBAdapter.fetchAllColours();

 startManagingCursor( coloursCursor);
/*Create an array to specify the fields we want to display in the list (only the 'colourName' column in this case) */

 String[] from = new String[]{TestDBAdapter.KEY_TITLE};
 /* and an array of the fields we want to bind those fields to (in this case just the textView 'tvDBViewRow' from our new db_view_row.xml layout above) */
 int[] to = new int[]{R.id.tvDBViewRow};

 /* Now create a simple cursor adapter.. */
 SimpleCursorAdapter colourAdapter =
 new SimpleCursorAdapter(this, R.layout.db_view_row, coloursCursor, from, to);

 /* and assign it to our Spinner widget */
 colourSpinner.setAdapter(colourAdapter);
 }




Update: Due to popular demand, here is a project that demonstrates this concept:
Spinner from Database example.


.. Let me know if you're having any access issues, it's just hosted publicly from my google docs.

Monday 19 March 2012

Android Adapters: an introduction

An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.

An AdapterView is a view whose children are determined by an Adapter.

Some examples of AdapterViews are ListView, GridView, Spinner and Gallery.


There are several types or sub-classes of Adapter:

ListAdapter: Extended Adapter that is the bridge between a ListView and the data that backs the list. Frequently that data comes from a Cursor, but that is not required. The ListView can display any data provided that it is wrapped in a ListAdapter.


ArrayAdapter: A ListAdapter that manages a ListView backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView.


CursorAdapter: Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named "_id" or this class will not work.


HeaderViewListAdapter: ListAdapter used when a ListView has header views. This ListAdapter wraps another one and also keeps track of the header views and their associated data objects.
This is intended as a base class; you will probably not need to use this class directly in your own code.


ResourceCursorAdapter: An easy adapter that creates views defined in an XML file. You can specify the XML file that defines the appearance of the views.


SimpleAdapter: An easy adapter to map static data to views defined in an XML file. You can specify the data backing the list as an ArrayList of Maps. Each entry in the ArrayList corresponds to one row in the list.


SimpleCursorAdapter: An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views.


SpinnerAdapter: Extended Adapter that is the bridge between a Spinner and its data. A spinner adapter allows to define two different views: one that shows the data in the spinner itself and one that shows the data in the drop down list when the spinner is pressed.


WrapperListAdapter: List adapter that wraps another list adapter. The wrapped adapter can be retrieved by calling getWrappedAdapter().

Monday 12 March 2012

Android in 3D


A 3d platform in android.That's 3D more feature and interesting


Example.java

package com.ex;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class Example extends Activity {
   
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new GLView2(this));
    }
   
}


GLView2

package com.ex;

import android.content.Context;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class GLView2 extends SurfaceView implements SurfaceHolder.Callback
{
 SurfaceHolder holder;
 ExThread gthread;
public GLView2(Context context) {
super(context);
// TODO Auto-generated constructor stub
getHolder().addCallback(this);
getHolder().setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
gthread=new ExThread(this);
gthread.start();

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub

}

}

GLThread.java


package com.ex;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGL11;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.content.Context;
import android.opengl.GLU;

import com.ex.GLView2;

public class ExThread extends Thread {
private final com.ex.GLView2 gview;
GLCube c=new GLCube();
private long startTime;
private boolean done = false;

public ExThread(com.ex.GLView2 view) {
// TODO Auto-generated constructor stub
this.gview=view;
}
public void run()
{
EGL10 gl=(EGL10)EGLContext.getEGL();
EGLDisplay display=gl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int version[]=new int[2];
gl.eglInitialize(display, version);
int[] configSpec = { EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };

EGLConfig[] configs = new EGLConfig[1];
int[] numConfig = new int[1];
gl.eglChooseConfig(display, configSpec, configs, 1,
numConfig);
EGLConfig config = configs[0];

EGLContext glc = gl.eglCreateContext(display, config,
EGL10.EGL_NO_CONTEXT, null);
EGLSurface surface = gl.eglCreateWindowSurface(display,
 config, gview.getHolder(), null);
 gl.eglMakeCurrent(display, surface, surface, glc);

 GL10 egl = (GL10) (glc.getGL());
 init(egl);
 while (!done) {
  // Draw a single frame here...
  drawFrame(egl);
  gl.eglSwapBuffers(display, surface);

  // Error handling
  if (gl.eglGetError() == EGL11.EGL_CONTEXT_LOST) {
  Context c = gview.getContext();
  if (c instanceof Activity) {
  ((Activity) c).finish();
  }
  }
 }
 gl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE,
  EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
  gl.eglDestroySurface(display, surface);
  gl.eglDestroyContext(display, glc);
  gl.eglTerminate(display);





}
private void drawFrame(GL10 egl) {
// TODO Auto-generated method stub
egl.glClear(GL10.GL_COLOR_BUFFER_BIT
| GL10.GL_DEPTH_BUFFER_BIT);
egl.glMatrixMode(GL10.GL_MODELVIEW);
egl.glLoadIdentity();
egl.glTranslatef(0, 0, -3.0f);
c.draw(egl);
long elapsed=System.currentTimeMillis()-startTime;
egl.glRotatef(elapsed *(30f/1000f), 0, 1,0);
egl.glRotatef(elapsed *(15f/1000f),1, 0,0);


}
private void init(GL10 egl) {

egl.glViewport(0, 0, gview.getWidth(), gview.getHeight());
egl.glMatrixMode(GL10.GL_PROJECTION);
egl.glLoadIdentity();
float ratio = (float) gview.getWidth() / gview.getHeight();
GLU.gluPerspective(egl, 45.0f, ratio, 1, 100f);

egl.glEnable(GL10.GL_DEPTH_TEST);
egl.glDepthFunc(GL10.GL_LEQUAL);
egl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
float lightAmbient[] = new float[] { 0.2f, 0.2f, 0.2f, 1 };
float lightDiffuse[] = new float[] { 1, 1, 1, 1 };
float[] lightPos = new float[] { 1, 1, 1, 1 };
egl.glEnable(GL10.GL_LIGHTING);
egl.glEnable(GL10.GL_LIGHT0);
egl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 0);
egl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 0);
egl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);
float matAmbient[] = new float[] { 1, 1, 1, 1 };
float matDiffuse[] = new float[] { 1, 1, 1, 1 };
egl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT,
matAmbient, 0);
egl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE,
matDiffuse, 0);
startTime=System.currentTimeMillis();

}
public void requestExitAndWait() {
// Tell the thread to quit
done = true;
try {
join();
} catch (InterruptedException ex) {
// Ignore
}
}

}

GLcube


package com.ex;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;

import javax.microedition.khronos.opengles.GL10;

public class GLCube {
private IntBuffer mvertexbuffer;
public GLCube()
{
int one=65536;
int half=one/2;
int vertices[]={-half, -half, half, half, -half, half,
- -half, half, half, half, half, half,
- // BACK
- -half, -half, -half, -half, half, -half,
- half, -half, -half, half, half, -half,
// LEFT
- -half, -half, half, -half, half, half,
- -half, -half, -half, -half, half, -half,
- // RIGHT
- half, -half, -half, half, half, -half,
half, -half, half, half, half, half,
- // TOP
- -half, half, half, half, half, half,
- -half, half, -half, half, half, -half,
- // BOTTOM
-half, -half, half, -half, -half, -half,
- half, -half, half, half, -half, -half};
ByteBuffer vbb=ByteBuffer.allocateDirect(vertices.length*4);
vbb.order(ByteOrder.nativeOrder());
mvertexbuffer=vbb.asIntBuffer();
mvertexbuffer.put(vertices);
mvertexbuffer.position(0);

}
public void draw(GL10 gl)
{

gl.glVertexPointer(3,GL10.GL_FIXED, 0,mvertexbuffer);

gl.glColor4f(1, 1,1,1);
gl.glNormal3f(0,0,1);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,0,4);
gl.glNormal3f(0,0, -1);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4,4);

gl.glColor4f(1, 1, 1, 1);
gl.glNormal3f(-1, 0, 0);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4);
gl.glNormal3f(1, 0, 0);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4);

gl.glColor4f(1, 1, 1, 1);
gl.glNormal3f(0, 1, 0);
 gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4);
 gl.glNormal3f(0, -1, 0);
 gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4);
}

}








Networking Concepts


package com.networkingex;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class NetworkingEx extends Activity {
    /** Called when the activity is first created. */
ImageView img;
   
private InputStream openHttpConnection(String urlstring)
throws IOException
{
InputStream in=null;
int response=-1;
URL url=new URL(urlstring);
URLConnection con=url.openConnection();
if(!(con instanceof URLConnection))
throw new IOException("NOT AN HTTP CONNECTION");
try{
HttpURLConnection httpcon=(HttpURLConnection)con;
httpcon.setAllowUserInteraction(false);
httpcon.setInstanceFollowRedirects(true);
httpcon.setRequestMethod("GET");
httpcon.connect();
response=httpcon.getResponseCode();
if(response==HttpURLConnection.HTTP_OK)
{
in=httpcon.getInputStream();
}

}catch(Exception e)
{
e.printStackTrace();
}

return in;

}
private Bitmap downloadImage(String url)
{
Bitmap bitmap=null;
InputStream in=null;
try
{
//in=openHttpConnection(url);
bitmap=BitmapFactory.decodeStream(openHttpConnection(url));
//in.close();
}catch(IOException e)
{
Toast.makeText(this, e.getLocalizedMessage(),Toast.LENGTH_LONG).show();
e.printStackTrace();

}
return bitmap;

}
private String downloadfile(String url)
{
int buffersize=200;
InputStream in=null;
try
{
in=openHttpConnection(url);
}catch(IOException e)
{
Toast.makeText(this,e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
InputStreamReader inr=new InputStreamReader(in);
int charread =0;
String str="";
char[] inputbuffer=new char[buffersize];
try
{
while((charread==inr.read(inputbuffer)))
{
String readline=String.copyValueOf(inputbuffer, 0,charread);
str+=readline;
inputbuffer=new char[buffersize];
}
in.close();
}catch(IOException e)
{
Toast.makeText(this,e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return url;

}
private String worddefinition(String word)
{
InputStream in=null;
String strDefinition="";
try
{
in=openHttpConnection("http://services.aonaware.com/DictService/DictService.asmx/Define?word="+word);
   Document doc=null;
   DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
   DocumentBuilder db;
   try
   {
    db=dbf.newDocumentBuilder();
    doc=db.parse(in);
   
   }catch(ParserConfigurationException e)
   {
    e.printStackTrace();
   }
   catch(Exception e)
   {
    e.printStackTrace();
   }
   doc.getDocumentElement().normalize();
   NodeList definitionElements=doc.getElementsByTagName("Definition");
 
 
  // NodeList definitionElements = null;
for(int i=0;i<definitionElements.getLength();i++)
   {

System.out.println("Lenght of Defintion:"+definitionElements.getLength());
Node item=definitionElements.item(1);
if(item.getNodeType()==Node.ELEMENT_NODE)
{
NodeList nodeList=item.getChildNodes();
strDefinition=nodeList.item(5).getTextContent();
/*//Element defElement=(Element)item;
NodeList wordDefinition=doc.getElementsByTagName("WordDefinition");
strDefinition="";
for(int j=0;j<wordDefinition.getLength();j++)
{
Element wordDefinitionElement =
(Element) wordDefinition.item(j);
NodeList textNodes =
((Node) wordDefinitionElement).getChildNodes();
strDefinition +=
((Node) textNodes.item(0)).getNodeValue() + ".";
}*/
/*NodeList nodeList=item.getChildNodes();
System.out.println("Lenght of Defintion:"+nodeList.getLength());

//System.out.println("Name::::::::::::::::2"+nodeList.item(2).getNodeName());
//System.out.println("Name:::::::::::::::3:"+nodeList.item(3).getNodeName());
//System.out.println("Name::::::::::::::::4"+nodeList.item(4).getNodeName());

Toast.makeText(getApplicationContext(),"Meaning is"+nodeList.item(5).getTextContent() , Toast.LENGTH_LONG).show();
//System.out.println("Name::::::::::::::::5"+nodeList.item(5).getTextContent());
*/
}
//return strDefinition;


   // NodeList itemnode= definitionElements.item(1);
   // System.out.println("Lenght of Defintion:"+itemnode.getLength());
    /*System.out.println("title:ln"+itemnode.getNodeName());
    System.out.println("title:nn"+itemnode.getNodeName());
    System.out.println("title:nv"+itemnode.getNodeValue());
    System.out.println("title:tc"+itemnode.getTextContent());*/
    /*if(itemnode.getNodeType()==Node.ELEMENT_NODE)
    {
    Log.d("mg","value is"+strDefinition);
    try
    {
    Element definitionelement=(Element)itemnode;
    }catch(Exception e)
    {
    Toast.makeText(getApplicationContext(), e.getLocalizedMessage(),Toast.LENGTH_LONG).show();
    }
   
    for(int j=0;j<wordDefinitionElements.getLength();j++)
    {
    Element wordelement=(Element)wordDefinitionElements.item(j);
    NodeList textnode=((Node)wordelement).getChildNodes();
    if(itemnode.getNodeName().equals("WordDefinition"))
    {
    strDefinition=itemnode.getNodeName();
    Log.d("msg is", "value is"+strDefinition);
    }
    //}
    Toast.makeText(getApplicationContext(),strDefinition, Toast.LENGTH_LONG).show();
    }*/



   
}
 



}catch(Exception e)
{
//Toast.makeText(getApplicationContext(),e.getLocalizedMessage(),Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return strDefinition;
}
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Bitmap bitmap = null;
        try
        {
         bitmap=downloadImage("http://cars.88000.org/wallpapers/80/Porsche_911_Police_Car.jpg");
        }catch(Exception e)
        {
        e.printStackTrace();
        }
       
       
        img=(ImageView)findViewById(R.id.imageView1);
        img.setImageBitmap(bitmap);
        /*String str="";
        try
        {
         str=downloadfile("http://appleinsider.com.feedsportal.com/c/33975/f/616168/index.rss");
        }catch(Exception e)
        {
        Toast.makeText(getApplicationContext(),str, 10000).show();
        e.printStackTrace();
        }
        try
        {
        String s=worddefinition("dry");
        TextView tv=new TextView(this);
        tv.setText(s);
        }catch(Exception e)
        {
        Toast.makeText(getApplicationContext(), e.getLocalizedMessage(),Toast.LENGTH_LONG).show();
        e.printStackTrace();
        }*/
    }
}



main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/icon">
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Button" android:background="@drawable/icon"></Button>
<ImageView android:id="@+id/imageView1"
android:layout_gravity="center"
android:layout_height="match_parent" android:layout_width="match_parent"></ImageView>
</LinearLayout>


Flickr with jason


package com.jasonex1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

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

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class JsonEx extends Activity {
   
   
String apikey1="733a667ca5dd461af38f81e7b1d0e7e8";
FlickrPhoto[] photos;
int [] ph={R.drawable.icon,R.drawable.icon};
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        HttpClient httpclient=new DefaultHttpClient();
        HttpGet httpget=new HttpGet("http://api.flickr.com/services/rest/?method=flickr.photos.search&tags=yourTag&format=json&api_key="+ apikey1 + "&per_page=5&nojsoncallback=1");
        HttpResponse response;
        try
        {
        response=httpclient.execute(httpget);
        HttpEntity entity=response.getEntity();
        if(entity!=null)
        {
        InputStream in=entity.getContent();
        BufferedReader br=new BufferedReader(new InputStreamReader(in));
        StringBuilder sb=new StringBuilder();
        String currentline="";
        try
        {
        while((currentline=br.readLine())!=null)
        {
        Log.d("line","current line data is"+currentline);
        sb.append(currentline+"\n");
        }
       
        }catch(IOException e)
        {
        e.printStackTrace();
        }
       
        String result=sb.toString();
        Log.d("result","result is"+result);
        JSONObject thedata=new JSONObject(result);
        JSONObject thephotosdata=thedata.getJSONObject("photos");
        JSONArray thephotodata=thephotosdata.getJSONArray("photo");
        photos=new FlickrPhoto[thephotodata.length()];
        for(int i=0;i<thephotodata.length();i++)
        {
        JSONObject photodata=thephotodata.getJSONObject(i);
        photos[i]=new FlickrPhoto(photodata.getString("id"),
        photodata.getString("owner"),photodata.getString("secret"),photodata.getString("server"),
        photodata.getString("title"),photodata.getString("farm"));
        }
        in.close();
       
        }
        }catch(Exception e)
        {
        e.printStackTrace();
        }
    ListView lv=(ListView)findViewById(R.id.listView1);
    lv.setAdapter(new FlickrEx(this,photos));
   
    }
    public  class FlickrEx extends BaseAdapter
    {
    Context con;
    private FlickrPhoto[] photos;
    LayoutInflater inflater;
    FlickrEx(Context c,FlickrPhoto[] items)
    {
    this.con=c;
    this.photos=items;
    inflater=(LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   
    }

@Override
public int getCount() {
// TODO Auto-generated method stub
return photos.length;
}

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

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View photorow=inflater.inflate(R.layout.row,null);
ImageView img=(ImageView)photorow.findViewById(R.id.ImageView);
img.setImageBitmap(imageFromUrl(photos[position].makeURL()));
TextView tv=(TextView)photorow.findViewById(R.id.TextView);
tv.setText("image");

return photorow;
}
public Bitmap imageFromUrl(String url)
{
Bitmap bitmap;
URL imageurl=null;
try
{
imageurl=new URL(url);
}catch(Exception e)
{
e.printStackTrace();
}
try
{
HttpURLConnection httpconnection=(HttpURLConnection)imageurl.openConnection();
httpconnection.setDoInput(true);
httpconnection.connect();
InputStream in=httpconnection.getInputStream();
bitmap=BitmapFactory.decodeStream(in);

}catch(Exception e)
{
e.printStackTrace();
bitmap=Bitmap.createBitmap(10,10,Bitmap.Config.ARGB_8888);

}


return bitmap;

}
   
    }
    class FlickrPhoto
    {
    String id;
    String owner;
    String secret;
    String server;
    String title;
    String farm;
    public FlickrPhoto(String id1,String owner1,String secret1,String server1,String title1,String farm1)
    {
    this.id=id1;
    this.owner=owner1;
    this.secret=secret1;
    this.server=server1;
    this.farm=farm1;
    this.title=title1;
   
    }
    public String makeURL()
    {
   
return "http://farm" + farm + ".static.flickr.com/" + server + "/"+ id + "_" + secret + "_m.jpg";
   
    }
    }
}

Jason Example


package com.jasonex;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class jasonEx extends Activity {
    /** Called when the activity is first created. */
   
private final static String jstring= "{\"person\":{\"name\":\"A\",\"age\":30,\"children\":[{\"name\":\"B\",\"age\":5}," + "{\"name\":\"C\",\"age\":7},{\"name\":\"D\",\"age\":9}]}}";

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tx1=(TextView)findViewById(R.id.textView1);
        TextView tx2=(TextView)findViewById(R.id.textView2);
        TextView tx3=(TextView)findViewById(R.id.textView3);
        try
        {
        JSONObject person=((new JSONObject(jstring)).getJSONObject("person"));
        String name=person.getString("name");
        Log.d("Name","name is"+name);
        tx1.setText("person name is"+name);
        tx2.setText(name+"is"+person.getInt("age")+"years old");
        tx3.setText(name+"has"+person.getJSONArray("children").length()+"chidren");
        }catch(JSONException e)
        {
        e.printStackTrace();
       
        }
       
    }
}

Creating your own keypad



    keypad.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hebrwKeyboardView" android:layout_width="fill_parent"
android:layout_alignParentBottom="true" android:layout_below="@+id/xsubLayout"
android:orientation="vertical" android:background="#252625"
android:visibility="visible" android:layout_height="180sp">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="200sp"
android:orientation="vertical" android:layout_alignParentBottom="true"
android:clipChildren="true">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="200sp"
android:padding="0sp">
<TableRow android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="0sp">
<LinearLayout android:baselineAligned="true"
android:layout_width="fill_parent" android:layout_height="45sp"
android:fitsSystemWindows="true">
<Button android:id="@+id/xQ" android:layout_width="30sp"
android:layout_height="fill_parent" android:text="Q"
android:textColor="#000" android:tag="Q" android:padding="0sp"
android:textStyle="bold" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xW"
android:layout_width="30sp" android:layout_height="fill_parent"
android:padding="0sp" android:textColor="#000" android:tag="W"
android:text="W" android:textStyle="bold" android:layout_gravity="left" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xE"
android:layout_gravity="left" android:layout_width="30sp"
android:padding="0sp" android:layout_height="fill_parent"
android:text="E" android:tag="E" android:textStyle="bold"
android:textColor="#000" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xR"
android:layout_width="30sp" android:layout_gravity="center_horizontal"
android:layout_height="fill_parent" android:text="R" android:tag="R"
android:textColor="#000" android:textStyle="bold"
android:fitsSystemWindows="true" android:ellipsize="marquee" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xT"
android:layout_width="33sp" android:layout_height="fill_parent"
android:layout_gravity="center_horizontal" android:text="T"
android:tag="T" android:fitsSystemWindows="true"
android:textColor="#000" android:textStyle="bold"
android:ellipsize="marquee" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xY"
android:layout_width="33sp" android:layout_height="fill_parent"
android:tag="y" android:layout_gravity="center" android:text="Y"
android:fitsSystemWindows="true" android:textColor="#000"
android:textStyle="bold" android:ellipsize="marquee" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xU"
android:layout_width="33sp" android:layout_gravity="center_horizontal"
android:layout_height="fill_parent" android:text="U" android:tag="U"
android:textColor="#000" android:textStyle="bold"
android:fitsSystemWindows="true" android:ellipsize="marquee" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xI"
android:layout_width="33sp" android:layout_height="fill_parent"
android:text="I" android:fitsSystemWindows="true" android:tag="I"
android:textColor="#000" android:textStyle="bold"
android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xO"
android:layout_width="33sp" android:layout_height="fill_parent"
android:text="O" android:fitsSystemWindows="true" android:tag="O"
android:textColor="#000" android:textStyle="bold"
android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xP"
android:layout_width="33sp" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold" android:text="P"
android:fitsSystemWindows="true" android:tag="P"
android:layout_gravity="center_horizontal" android:ellipsize="marquee" />
</LinearLayout>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="45sp">
<Button android:layout_alignWithParentIfMissing="true"
android:soundEffectsEnabled="true" android:id="@+id/xA"
android:layout_width="30sp" android:layout_centerHorizontal="true"
android:tag="A" android:layout_gravity="center_horizontal|center_vertical|center"
android:textColor="#000" android:textStyle="bold"
android:layout_height="fill_parent" android:text="A"
android:layout_alignParentLeft="true" android:fitsSystemWindows="true" />
<Button android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:layout_toRightOf="@id/xA"
android:id="@+id/xS" android:layout_width="30sp" android:tag="S"
android:layout_gravity="center_horizontal|center_vertical|center"
android:layout_height="fill_parent" android:text="S"
android:textColor="#000" android:textStyle="bold"
android:layout_alignWithParentIfMissing="true"
android:fitsSystemWindows="true" />
<Button android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:id="@+id/xD"
android:layout_toRightOf="@id/xS" android:layout_width="30sp"
android:layout_gravity="center_horizontal|center_vertical|center"
android:textColor="#000" android:textStyle="bold" android:tag="D"
android:layout_height="fill_parent" android:text="D"
android:fitsSystemWindows="true" />
<Button android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:id="@+id/xF"
android:layout_toRightOf="@id/xD" android:layout_width="30sp"
android:tag="F" android:layout_gravity="center_horizontal|center_vertical|center"
android:layout_height="fill_parent" android:text="F"
android:textColor="#000" android:textStyle="bold"
android:fitsSystemWindows="true" />
<Button android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:id="@+id/xG"
android:layout_toRightOf="@id/xF" android:layout_width="33sp"
android:textColor="#000" android:textStyle="bold"
android:layout_height="fill_parent" android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="G" android:text="G" android:fitsSystemWindows="true" />
<Button android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:id="@+id/xH"
android:layout_toRightOf="@id/xG" android:layout_width="33sp"
android:tag="H" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold"
android:layout_gravity="center_horizontal|center_vertical|center"
android:text="H" android:fitsSystemWindows="true" />
<Button android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:id="@+id/xJ"
android:layout_toRightOf="@id/xH" android:layout_width="33sp"
android:textColor="#000" android:textStyle="bold"
android:layout_height="fill_parent" android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="J" android:text="J" android:fitsSystemWindows="true" />
<Button android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:id="@+id/xK"
android:textColor="#000" android:textStyle="bold"
android:layout_toRightOf="@id/xJ" android:layout_width="33sp"
android:layout_height="fill_parent" android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="K" android:text="K" android:fitsSystemWindows="true" />
<Button android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:id="@+id/xL"
android:textColor="#000" android:textStyle="bold"
android:layout_toRightOf="@id/xK" android:layout_width="33sp"
android:layout_height="fill_parent" android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="L" android:text="L" android:fitsSystemWindows="true" />
<Button android:layout_alignWithParentIfMissing="true"
android:layout_centerHorizontal="true"
android:soundEffectsEnabled="true" android:id="@+id/xS1"
android:layout_toRightOf="@id/xL" android:layout_width="33sp"
android:textColor="#000" android:textStyle="bold"
android:layout_height="fill_parent" android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="ç" android:text="ç" android:fitsSystemWindows="true" />
</RelativeLayout>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="fill_vertical"
android:fitsSystemWindows="true" android:orientation="horizontal">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="45sp" android:gravity="bottom"
android:orientation="horizontal">
<Button android:soundEffectsEnabled="true" android:id="@+id/xS2"
android:layout_width="30sp" android:layout_gravity="center_horizontal|center_vertical|center"
android:textColor="#000" android:textStyle="bold"
android:layout_height="fill_parent" android:text="à" android:tag="à"
android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xZ"
android:layout_width="30sp" android:layout_gravity="center_horizontal|center_vertical|center"
android:layout_height="fill_parent" android:text="Z" android:tag="Z"
android:textColor="#000" android:textStyle="bold"
android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xX"
android:layout_width="30sp" android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="X" android:layout_height="fill_parent" android:text="X"
android:textColor="#000" android:textStyle="bold"
android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xC"
android:layout_width="30sp" android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="C" android:layout_height="fill_parent" android:text="C"
android:textColor="#000" android:textStyle="bold"
android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xV"
android:layout_width="30sp" android:layout_height="fill_parent"
android:layout_gravity="center_horizontal|center_vertical|center"
android:textColor="#000" android:textStyle="bold" android:tag="V"
android:text="V" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xB"
android:layout_width="33sp" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold"
android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="B" android:text="B" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xN"
android:layout_width="33sp" android:layout_height="fill_parent"
android:layout_gravity="center_horizontal|center_vertical|center"
android:textColor="#000" android:textStyle="bold" android:tag="N"
android:text="N" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xM"
android:layout_width="33sp" android:layout_height="fill_parent"
android:layout_gravity="center_horizontal|center_vertical|center"
android:textColor="#000" android:textStyle="bold" android:tag="M"
android:text="M" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xS3"
android:layout_width="33sp" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold" android:tag="é"
android:layout_gravity="center_horizontal|center_vertical|center"
android:text="é" android:fitsSystemWindows="true" />

<Button android:soundEffectsEnabled="true" android:id="@+id/xBack"
android:layout_width="33sp" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold" android:tag="back"
android:layout_gravity="center_horizontal|center_vertical|center"
android:fitsSystemWindows="true" android:background="@drawable/back_high" />


</LinearLayout>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fitsSystemWindows="true"
android:orientation="horizontal">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="45sp" android:gravity="bottom"
android:orientation="horizontal">
<Button android:soundEffectsEnabled="true" android:id="@+id/xChange"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold"
android:layout_gravity="right" android:fitsSystemWindows="true"
android:paddingLeft="35sp" android:tag="upper" android:background="@drawable/change" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xS4"
android:layout_width="33sp" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold"
android:layout_gravity="right" android:fitsSystemWindows="true"
android:tag="è" android:text="è" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xSpace"
android:textColor="#000" android:textStyle="bold"
android:layout_width="75sp" android:layout_height="fill_parent"
android:tag=" " android:text="|_____|" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xS5"
android:layout_width="30sp" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold"
android:layout_gravity="center_horizontal|center_vertical|center"
android:tag="û" android:text="û" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xS6"
android:layout_width="30sp" android:layout_height="fill_parent"
android:layout_gravity="center_horizontal|center_vertical|center"
android:textColor="#000" android:textStyle="bold" android:tag="î"
android:text="î" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xNum"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:textColor="#000" android:textStyle="bold" android:tag="num"
android:text="12#" android:fitsSystemWindows="true" />
<Button android:soundEffectsEnabled="true" android:id="@+id/xDone"
android:layout_width="40sp" android:layout_height="fill_parent"
android:layout_gravity="right" android:background="@drawable/hide_high"
android:textColor="#000" android:textStyle="bold" android:tag="done"
android:fitsSystemWindows="true" />
</LinearLayout>
</TableRow>
</TableLayout>
</TableLayout>
</RelativeLayout>

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/xMLayout"
android:background="#000000" android:layout_height="fill_parent"
android:focusable="true"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/xsubLayout"
android:keepScreenOn="true" android:orientation="vertical"
android:layout_height="fill_parent">
<EditText android:id="@+id/xEt" android:layout_width="fill_parent"
android:focusableInTouchMode="true" android:layout_height="wrap_content" />
<EditText android:id="@+id/et1" android:layout_width="fill_parent"
android:layout_below="@+id/xEt" android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:id="@+id/xK1"
android:layout_height="wrap_content" android:orientation="vertical"
android:visibility="gone">
<include android:id="@+id/xKeyBoard" layout="@layout/keyboard"></include>
</RelativeLayout>
</RelativeLayout>


package com.mykey;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

public class MyKey extends Activity implements OnTouchListener,OnClickListener,OnFocusChangeListener {
    /** Called when the activity is first created. */
   
EditText et1,et2;
private Button mBSpace, mBdone, mBack, mBChange, mNum;
private RelativeLayout mLayout, mKLayout;
private boolean isEdit = false, isEdit1 = false;
private String mUpper = "upper", mLower = "lower";
private int w, mWindowWidth;
private String sL[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
"x", "y", "z", "ç", "à ", "é", "è", "û", "î" };
private String cL[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z", "ç", "à ", "é", "è", "û", "î" };
private String nS[] = { "!", ")", "'", "#", "3", "$", "%", "&", "8", "*",
"?", "/", "+", "-", "9", "0", "1", "4", "@", "5", "7", "(", "2",
"\"", "6", "_", "=", "]", "[", "<", ">", "|" };
private Button mB[] = new Button[32];
   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try
        {
        setContentView(R.layout.main);
        setKeys();
setFrow();
setSrow();
setTrow();
setForow();
et1 = (EditText) findViewById(R.id.xEt);
et1.setOnTouchListener(this);
et1.setOnFocusChangeListener(this);
et2 = (EditText) findViewById(R.id.et1);

et2.setOnTouchListener(this);
et2.setOnFocusChangeListener(this);
et1.setOnClickListener(this);
et2.setOnClickListener(this);
mLayout = (RelativeLayout) findViewById(R.id.xK1);
mKLayout = (RelativeLayout) findViewById(R.id.xKeyBoard);
       
       
       
        }catch (Exception e)
        {
        e.printStackTrace();
        }
     
       
    }

private void setFrow() {
w = (mWindowWidth / 13);
w = w - 15;
mB[16].setWidth(w);
mB[22].setWidth(w + 3);
mB[4].setWidth(w);
mB[17].setWidth(w);
mB[19].setWidth(w);
mB[24].setWidth(w);
mB[20].setWidth(w);
mB[8].setWidth(w);
mB[14].setWidth(w);
mB[15].setWidth(w);
mB[16].setHeight(50);
mB[22].setHeight(50);
mB[4].setHeight(50);
mB[17].setHeight(50);
mB[19].setHeight(50);
mB[24].setHeight(50);
mB[20].setHeight(50);
mB[8].setHeight(50);
mB[14].setHeight(50);
mB[15].setHeight(50);

}

private void setTrow() {
w = (mWindowWidth / 12);
mB[25].setWidth(w);
mB[23].setWidth(w);
mB[2].setWidth(w);
mB[21].setWidth(w);
mB[1].setWidth(w);
mB[13].setWidth(w);
mB[12].setWidth(w);
mB[27].setWidth(w);
mB[28].setWidth(w);
mBack.setWidth(w);

mB[25].setHeight(50);
mB[23].setHeight(50);
mB[2].setHeight(50);
mB[21].setHeight(50);
mB[1].setHeight(50);
mB[13].setHeight(50);
mB[12].setHeight(50);
mB[27].setHeight(50);
mB[28].setHeight(50);
mBack.setHeight(50);

}

private void setSrow() {
w = (mWindowWidth / 10);
mB[0].setWidth(w);
mB[18].setWidth(w);
mB[3].setWidth(w);
mB[5].setWidth(w);
mB[6].setWidth(w);
mB[7].setWidth(w);
mB[26].setWidth(w);
mB[9].setWidth(w);
mB[10].setWidth(w);
mB[11].setWidth(w);
mB[26].setWidth(w);

mB[0].setHeight(50);
mB[18].setHeight(50);
mB[3].setHeight(50);
mB[5].setHeight(50);
mB[6].setHeight(50);
mB[7].setHeight(50);
mB[9].setHeight(50);
mB[10].setHeight(50);
mB[11].setHeight(50);
mB[26].setHeight(50);
}

private void setForow() {
w = (mWindowWidth / 10);
mBSpace.setWidth(w * 4);
mBSpace.setHeight(50);
mB[29].setWidth(w);
mB[29].setHeight(50);

mB[30].setWidth(w);
mB[30].setHeight(50);

mB[31].setHeight(50);
mB[31].setWidth(w);
mBdone.setWidth(w + (w / 1));
mBdone.setHeight(50);

}

private void setKeys() {
// TODO Auto-generated method stub
mWindowWidth=getWindowManager().getDefaultDisplay().getWidth();
mB[0]=(Button)findViewById(R.id.xA);
mB[1]=(Button)findViewById(R.id.xB);
mB[2]=(Button)findViewById(R.id.xC);
mB[3]=(Button)findViewById(R.id.xD);
mB[4]=(Button)findViewById(R.id.xE);
mB[5]=(Button)findViewById(R.id.xF);
mB[6]=(Button)findViewById(R.id.xG);
mB[7]=(Button)findViewById(R.id.xH);
mB[8]=(Button)findViewById(R.id.xI);
mB[9]=(Button)findViewById(R.id.xJ);
mB[10]=(Button)findViewById(R.id.xK);
mB[11]=(Button)findViewById(R.id.xL);
mB[12]=(Button)findViewById(R.id.xM);
mB[13]=(Button)findViewById(R.id.xN);
mB[14]=(Button)findViewById(R.id.xO);
mB[15]=(Button)findViewById(R.id.xP);
mB[16]=(Button)findViewById(R.id.xQ);
mB[17]=(Button)findViewById(R.id.xR);
mB[18]=(Button)findViewById(R.id.xS);
mB[19]=(Button)findViewById(R.id.xT);
mB[20]=(Button)findViewById(R.id.xU);
mB[21]=(Button)findViewById(R.id.xV);
mB[22]=(Button)findViewById(R.id.xW);
mB[23]=(Button)findViewById(R.id.xX);
mB[24]=(Button)findViewById(R.id.xY);
mB[25]=(Button)findViewById(R.id.xZ);
mB[26]=(Button)findViewById(R.id.xS1);
mB[27]=(Button)findViewById(R.id.xS2);
mB[28]=(Button)findViewById(R.id.xS3);
mB[29]=(Button)findViewById(R.id.xS4);
mB[30]=(Button)findViewById(R.id.xS5);
mB[31]=(Button)findViewById(R.id.xS6);
mBSpace=(Button)findViewById(R.id.xSpace);
mBdone=(Button)findViewById(R.id.xDone);
mBChange=(Button)findViewById(R.id.xChange);
mBack=(Button)findViewById(R.id.xBack);
mNum=(Button)findViewById(R.id.xNum);
for(int i=0;i<mB.length;i++)
mB[i].setOnClickListener(this);
mBSpace.setOnClickListener(this);
mBdone.setOnClickListener(this);
mBack.setOnClickListener(this);
mBChange.setOnClickListener(this);
mNum.setOnClickListener(this);



}

@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(v==et1)
{
hideDefaultKeyboard();
enableKeyboard();

}
if(v==et2)
{
hideDefaultKeyboard();
enableKeyboard();
}
return true;
}

private void enableKeyboard() {
// TODO Auto-generated method stub
mLayout.setVisibility(RelativeLayout.VISIBLE);
mKLayout.setVisibility(RelativeLayout.VISIBLE);

}

private void hideDefaultKeyboard() {
// TODO Auto-generated method stub
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==mBChange)
{
if(mBChange.getTag().equals(mUpper))
{
changeSmallLetters();
changeSmallTags();

}
else if(mBChange.getTag().equals(mLower))
{
changeCapitalLetters();
changeCaptialTags();
}
}else if(v!=mBdone && v!=mBack && v!=mBChange && v!=mNum)
{
addText(v);
}else if(v==mBdone)
{
disableKeyboard();
}else if(v==mBack)
{
isBack(v);
}else if(v==mNum)
{
String tag=(String)mNum.getTag();
if(tag.equals("num"))
{
changeSyNuLetters();
changeSyNuTags();
mBChange.setVisibility(Button.INVISIBLE);
}
if(tag.equals("ABC"))
{
changeCapitalLetters();
changeCaptialTags();
}
}

}

private void disableKeyboard() {
// TODO Auto-generated method stub
mLayout.setVisibility(RelativeLayout.INVISIBLE);
mKLayout.setVisibility(RelativeLayout.INVISIBLE);


}

private void changeSyNuTags() {
// TODO Auto-generated method stub
for(int i=0;i<nS.length;i++)
mB[i].setTag(sL[i]);
mNum.setTag("ABC");

}

private void changeSyNuLetters() {
// TODO Auto-generated method stub
for(int i=0;i<nS.length;i++)
mB[i].setText(nS[i]);
mNum.setTag("ABC");




}

private void changeCaptialTags() {
// TODO Auto-generated method stub
for(int i=0;i<cL.length;i++)
mB[i].setTag(cL[i]);
//mBChange.setTag("upper");
mNum.setText("num");

}

private void changeCapitalLetters() {
// TODO Auto-generated method stub
mBChange.setVisibility(Button.VISIBLE);
for(int i=0;i<cL.length;i++)
mB[i].setText(cL[i]);
mBChange.setTag("upper");
mNum.setTag("12#");
}

private void changeSmallTags() {
// TODO Auto-generated method stub
for(int i=0;i<sL.length;i++)
mB[i].setTag(sL[i]);
mBChange.setTag("lower");
mNum.setTag("num");

}

private void changeSmallLetters() {
// TODO Auto-generated method stub
mBChange.setVisibility(Button.VISIBLE);
for(int i=0;i<sL.length;i++)
mB[i].setText(sL[i]);
mNum.setTag("12#");

}

private void isBack(View v) {
// TODO Auto-generated method stub
if(isEdit==true)
{
CharSequence cc=et1.getText();
if(cc!=null && cc.length()>0)
{
et1.setText("");
et1.append(cc.subSequence(0, cc.length()-1));
}
}
if(isEdit1==false)
{
CharSequence cc=et2.getText();
if(cc!=null && cc.length()>0)
{
et2.setText("");
et2.append(cc.subSequence(0, cc.length()-1));
}
}

}

private void addText(View v) {
// TODO Auto-generated method stub
if(isEdit==true)
{
String b;
b=(String)v.getTag();
if(b!=null)
{
et1.append(b);
}
}
if(isEdit1==true)
{
String c;
c=(String)v.getTag();
if(c!=null)
{
et2.append(c);
}
}

}

@Override
public void onFocusChange(View v, boolean hasFocus) {
if (v == et1 && hasFocus == true) {
isEdit = true;
isEdit1 = false;

} else if (v == et2 && hasFocus == true) {
isEdit = false;
isEdit1 = true;

}

}
}