<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4613043958095018301</id><updated>2026-02-26T01:46:22.456-08:00</updated><title type='text'>Imran khan&#39;s Blog- Android</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>36</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-3784977026463086010</id><published>2012-07-03T15:05:00.000-07:00</published><updated>2012-07-03T15:05:20.256-07:00</updated><title type='text'>Android : CharacterPickerDialog Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsrWEU4ss8EYW7LbqGIt-_9XjsMPz0JkFHWW9NK5tlv1YVapwfuI3UbEDku6q0wyb2-NTGamPbRFntgXF0GcCDPmaKnDXq8mXM5AJH-Phb6djeJ3WGcC7Lj8PDMMI-C15xgv_9bHT7ZUI/s1600/Android_CharacterPickerDialog_Example_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsrWEU4ss8EYW7LbqGIt-_9XjsMPz0JkFHWW9NK5tlv1YVapwfuI3UbEDku6q0wyb2-NTGamPbRFntgXF0GcCDPmaKnDXq8mXM5AJH-Phb6djeJ3WGcC7Lj8PDMMI-C15xgv_9bHT7ZUI/s400/Android_CharacterPickerDialog_Example_1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;





&lt;/td&gt;
&lt;td&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPdc85UrWGs85uLqU7Zmrer48KsoWAdjMmqBFfZPD7bn-59SgzdCebd7rGPCXYkuE3AMMB49pyxYJ66c2YZXF9u3MBeDBKZ0ovIEmykBpbF-Xfu3b6Fw2Y7Vr8A2xH-ul4nPBYrKja6PE/s1600/Android_CharacterPickerDialog_Example_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPdc85UrWGs85uLqU7Zmrer48KsoWAdjMmqBFfZPD7bn-59SgzdCebd7rGPCXYkuE3AMMB49pyxYJ66c2YZXF9u3MBeDBKZ0ovIEmykBpbF-Xfu3b6Fw2Y7Vr8A2xH-ul4nPBYrKja6PE/s400/Android_CharacterPickerDialog_Example_2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;




&lt;/td&gt;

&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;b&gt;main.xml:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

        &amp;lt;Button
        android:id=&quot;@+id/Button01&quot;
        android:layout_gravity=&quot;center&quot;
        android:layout_marginTop=&quot;40dp&quot;
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;CharacterPickerDialog&quot; /&gt;

&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;CharacterPickerDialogActivity.java:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class CharacterPickerDialogActivity extends Activity {
    /** Called when the activity is first created. */
 private CharacterPickerDialog cpd = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button button = (Button) this.findViewById(R.id.Button01);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cpd.show();
            }
        });
          String options=&quot;0123456789ABCDEF&quot;;  
          cpd= new CharacterPickerDialog(this, new View(this), null,options,false){ 
           public void onClick(View v) {
                     
                     Toast.makeText(getApplicationContext(),
                             &quot;onClick! &quot; + ((Button) v).getText().toString(),
                             Toast.LENGTH_SHORT).show();
                     dismiss();
            }
           public void onItemClick(AdapterView parent, View view, int position, long id)
                 {
                     
                     String message = (&quot;onItemClick! &quot; + ((Button) view).getText().toString())
                             + &quot; position=&quot; +
                             position
                             + &quot; id=&quot; + id;
                     Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
                     dismiss();
                 }
      };
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/CharacterPickerDialogExample.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_CharacterPickerDialog_Example&quot; target=&quot;_blank&quot;&gt;CharacterPickerDialogExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/3784977026463086010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/07/android-characterpickerdialog-example.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/3784977026463086010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/3784977026463086010'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/07/android-characterpickerdialog-example.html' title='Android : CharacterPickerDialog Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsrWEU4ss8EYW7LbqGIt-_9XjsMPz0JkFHWW9NK5tlv1YVapwfuI3UbEDku6q0wyb2-NTGamPbRFntgXF0GcCDPmaKnDXq8mXM5AJH-Phb6djeJ3WGcC7Lj8PDMMI-C15xgv_9bHT7ZUI/s72-c/Android_CharacterPickerDialog_Example_1.png" height="72" width="72"/><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-7130294306976778790</id><published>2012-07-03T13:56:00.000-07:00</published><updated>2012-07-03T13:56:33.733-07:00</updated><title type='text'>Android : Crop Image in Android</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZckZB0p20M_QWmR-OdfomR4OwzE5OlkMyDkFG78lDMi5bP91nvIHu5l2Q290hsyWznDdBK8dJ5f1sXGLTQ-pRaTMcB0_G3XtFPrE0H5Lv9l0Blqa_x2WnsqUAowi_faTeH9x5VoLUOJ4/s1600/Android_Crop_Image_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZckZB0p20M_QWmR-OdfomR4OwzE5OlkMyDkFG78lDMi5bP91nvIHu5l2Q290hsyWznDdBK8dJ5f1sXGLTQ-pRaTMcB0_G3XtFPrE0H5Lv9l0Blqa_x2WnsqUAowi_faTeH9x5VoLUOJ4/s400/Android_Crop_Image_1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;



&lt;/td&gt;
&lt;td&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgybwMdNTfQkvSz_QPTGGumbMlKEWl66eIZiOQztr_vyyHHq-S9Ig2jtRHFcHA-SoMmIb78rrAwBFRD7jzsfGSqrw6EfXIwSKpQof4Ck_C4tdopGOGs77yU04b3OP6EIiH-tAnuOcwZ_RA/s1600/Android_Crop_Image_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgybwMdNTfQkvSz_QPTGGumbMlKEWl66eIZiOQztr_vyyHHq-S9Ig2jtRHFcHA-SoMmIb78rrAwBFRD7jzsfGSqrw6EfXIwSKpQof4Ck_C4tdopGOGs77yU04b3OP6EIiH-tAnuOcwZ_RA/s400/Android_Crop_Image_2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;/td&gt;

&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;b&gt;main.xml:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;
 &amp;lt;ImageView 
     android:id=&quot;@+id/imageuri&quot;
      android:layout_marginTop=&quot;15dp&quot;
     android:adjustViewBounds=&quot;true&quot;
     android:layout_gravity=&quot;center&quot;
     android:maxWidth=&quot;250dip&quot;
        android:maxHeight=&quot;250dip&quot; 
        android:layout_width=&quot;wrap_content&quot;
     android:layout_height=&quot;wrap_content&quot; /&gt;
  &amp;lt;Button 
     android:id=&quot;@+id/btncropimg&quot; 
      android:layout_gravity=&quot;center&quot;
      android:layout_marginTop=&quot;15dp&quot;
     android:layout_height=&quot;50dip&quot;
        android:text=&quot;Crop Image&quot; 
        android:layout_width=&quot;150dip&quot;/&gt;
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;TestCropActivity.java:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class TestCropActivity extends Activity {
    /** Called when the activity is first created. */
 private File tempFile;
 public static final int NONE = 0;
 ImageView imageView = null;
 Button buttoncrop = null;
 Uri imgUri;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        
        imageView=(ImageView)findViewById(R.id.imageuri);
        buttoncrop=(Button)findViewById(R.id.btncropimg);
        //image URI from SDCARD
        tempFile = new File(Environment.getExternalStorageDirectory()+&quot;/Images/a07.jpg&quot;);
        imgUri=Uri.fromFile(tempFile);
        imageView.setImageURI(imgUri);
        buttoncrop.setOnClickListener(btncroplistener);
    }
    private OnClickListener btncroplistener=new OnClickListener() { 
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub

   startCrop(imgUri);
  }
 };
 public void startCrop(Uri uri) {
       
        Intent intent = new Intent(&quot;com.android.camera.action.CROP&quot;);  
        //intent.setClassName(&quot;com.android.camera&quot;, &quot;com.android.camera.CropImage&quot;); 
        intent.setDataAndType(uri, &quot;image/*&quot;);
        intent.putExtra(&quot;crop&quot;, &quot;true&quot;);
     // aspectX aspectY  width and height ratio
        intent.putExtra(&quot;aspectX&quot;, 1);
        intent.putExtra(&quot;aspectY&quot;, 1);
        // outputX outputY Crop picture width and height
        intent.putExtra(&quot;outputX&quot;, 96); 
        intent.putExtra(&quot;outputY&quot;, 96);
        //output file Uri where Cropped image save
        intent.putExtra(&quot;output&quot;, Uri.fromFile(tempFile)); 
        intent.putExtra(&quot;outputFormat&quot;, &quot;JPEG&quot;);
        startActivityForResult(intent, 1);  
 }
    @Override
 protected void onActivityResult(int requestCode,int resultCode,Intent data){
  if(requestCode==NONE)
   return;
  if(data==null)
   return;
  if(requestCode==1){
   Bundle extras=data.getExtras();
   if(extras !=null){
    //get cropped image here from data as Bitmap
    Bitmap photo=extras.getParcelable(&quot;data&quot;);
    ByteArrayOutputStream stream=new ByteArrayOutputStream();
    photo.compress(Bitmap.CompressFormat.JPEG, 75, stream);
    imageView.setImageBitmap(photo);
   }
  }
  super.onActivityResult(requestCode, resultCode, data);
 }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/TestCrop1.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_Crop_Image_Example&quot; target=&quot;_blank&quot;&gt;CropImage&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/7130294306976778790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/07/android-crop-image-in-android.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/7130294306976778790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/7130294306976778790'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/07/android-crop-image-in-android.html' title='Android : Crop Image in Android'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZckZB0p20M_QWmR-OdfomR4OwzE5OlkMyDkFG78lDMi5bP91nvIHu5l2Q290hsyWznDdBK8dJ5f1sXGLTQ-pRaTMcB0_G3XtFPrE0H5Lv9l0Blqa_x2WnsqUAowi_faTeH9x5VoLUOJ4/s72-c/Android_Crop_Image_1.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-3801760648480842956</id><published>2012-06-25T13:29:00.000-07:00</published><updated>2012-06-25T13:29:14.878-07:00</updated><title type='text'>Android SpannableStringBuilder Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT8evmV8CLh7goQDWSpLJ-jZXU0hH1RFRd1Q-JiVgj32xZRNnkv7LT6LXy_R_Y4KGZVl07K0lMtR_kfNlyvDIf5fu27KPIHsTGho1ie0s0gBT9WJPDELZz0Bgczr5_KNJ6qnLOl5LRvIs/s1600/Android_SpannableStringBuilder_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT8evmV8CLh7goQDWSpLJ-jZXU0hH1RFRd1Q-JiVgj32xZRNnkv7LT6LXy_R_Y4KGZVl07K0lMtR_kfNlyvDIf5fu27KPIHsTGho1ie0s0gBT9WJPDELZz0Bgczr5_KNJ6qnLOl5LRvIs/s400/Android_SpannableStringBuilder_1.png&quot; /&gt;&lt;/a&gt;

&lt;/td&gt;

&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;b&gt;main.xml:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

&amp;lt;EditText 
        android:id=&quot;@+id/editText1&quot;
        android:layout_marginTop=&quot;10dp&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:textSize=&quot;50.0dp&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;@string/hello&quot; /&gt;
&amp;lt;TextView 
        android:id=&quot;@+id/txtview&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:textSize=&quot;25.0dp&quot;
        android:gravity=&quot;center&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;SpannableStringBuilder&quot; /&gt;
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;SpannableStringBuilderActivity.java:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class SpannableStringBuilderActivity extends Activity {
 private EditText et;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
  et = (EditText) this.findViewById(R.id.editText1);
  et.setText(&quot;HelloWorld&quot;);
  this.setstyle(3, 7);
    }
 public void setstyle(int start, int end) {
  SpannableStringBuilder spannable = new SpannableStringBuilder(getText()
    .toString());
  CharacterStyle span1 = new UnderlineSpan();
  spannable.setSpan(span1, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  ForegroundColorSpan span2 = new ForegroundColorSpan(Color.RED);
  spannable.setSpan(span2, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
   CharacterStyle span3=new StyleSpan(android.graphics.Typeface.ITALIC); 
   spannable.setSpan(span3, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  setText(spannable);
 }
 private Editable getText() {
  return et.getText();
 }

 private void setText(SpannableStringBuilder spannalbe) {
  et.setText(spannalbe);

 }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/SpannableStringBuilder.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_SpannableStringBuilder_Example&quot; target=&quot;_blank&quot;&gt;SpannableStringBuilder&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/3801760648480842956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-spannablestringbuilder-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/3801760648480842956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/3801760648480842956'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-spannablestringbuilder-example.html' title='Android SpannableStringBuilder Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjT8evmV8CLh7goQDWSpLJ-jZXU0hH1RFRd1Q-JiVgj32xZRNnkv7LT6LXy_R_Y4KGZVl07K0lMtR_kfNlyvDIf5fu27KPIHsTGho1ie0s0gBT9WJPDELZz0Bgczr5_KNJ6qnLOl5LRvIs/s72-c/Android_SpannableStringBuilder_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-3641862577581838256</id><published>2012-06-25T13:22:00.002-07:00</published><updated>2012-06-25T13:22:45.806-07:00</updated><title type='text'>Android  TextWatcher Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;div&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZI29M-B-OvtBURwEfbLigfKjTf9MgOSpZeT4wSeBK1ATZks5JMP4oHXnjb5PcTz4lHIxX_ewuBwMA3ostsQ7RM2fyTaC319KnuoG1sY4QEpNKBE0HTe3OVVpmboPSvZkf3CzugDg5sR8/s1600/Android_TextWatcher_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZI29M-B-OvtBURwEfbLigfKjTf9MgOSpZeT4wSeBK1ATZks5JMP4oHXnjb5PcTz4lHIxX_ewuBwMA3ostsQ7RM2fyTaC319KnuoG1sY4QEpNKBE0HTe3OVVpmboPSvZkf3CzugDg5sR8/s400/Android_TextWatcher_1.png&quot; /&gt;&lt;/a&gt;






&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;b&gt;main.xml:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

    &amp;lt;EditText 
        android:id=&quot;@+id/entry&quot;
        android:layout_marginTop=&quot;10dp&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;@string/hello&quot; /&gt;
&amp;lt;TextView 
        android:id=&quot;@+id/txtview1&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:textSize=&quot;25.0dp&quot;
        android:gravity=&quot;center&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;TextWatcher&quot; /&gt;
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;MaxLengthWatcher.java:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class MaxLengthWatcher implements TextWatcher {  
  
    private int maxLen = 0;  
    private EditText editText = null;  
      
      
    public MaxLengthWatcher(int maxLen, EditText editText) {  
        this.maxLen = maxLen;  
        this.editText = editText;  
    }  
  
    public void afterTextChanged(Editable arg0) {  
        // TODO Auto-generated method stub  
          
    }  
  
    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,  
            int arg3) {  
        // TODO Auto-generated method stub  
          
    }  
  
    public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {  
        // TODO Auto-generated method stub  
        Editable editable = editText.getText();  
        int len = editable.length();  
          
        if(len &gt; maxLen)  
        {  
            int selEndIndex = Selection.getSelectionEnd(editable);  
            String str = editable.toString();  
            //Interception of a new string 
            String newStr = str.substring(0,maxLen);  
            editText.setText(newStr);  
            editable = editText.getText();           
            int newLen = editable.length();  
            if(selEndIndex &gt; newLen)  
            {  
                selEndIndex = editable.length();  
            }  
            //Set the new cursor position 
            Selection.setSelection(editable, selEndIndex);  
              
        }  
    }  
}
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;TextWatcherActivity.java :&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class TextWatcherActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        EditText editText = (EditText) findViewById(R.id.entry);  
        editText.addTextChangedListener(new MaxLengthWatcher(10, editText));  
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/AndroidTextWatcher.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_TextWatcher_Example&quot; target=&quot;_blank&quot;&gt;AndroidTextWatcher&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/3641862577581838256/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-textwatcher-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/3641862577581838256'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/3641862577581838256'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-textwatcher-example.html' title='Android  TextWatcher Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZI29M-B-OvtBURwEfbLigfKjTf9MgOSpZeT4wSeBK1ATZks5JMP4oHXnjb5PcTz4lHIxX_ewuBwMA3ostsQ7RM2fyTaC319KnuoG1sY4QEpNKBE0HTe3OVVpmboPSvZkf3CzugDg5sR8/s72-c/Android_TextWatcher_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-2544810334337774673</id><published>2012-06-25T13:14:00.001-07:00</published><updated>2012-06-25T13:30:50.442-07:00</updated><title type='text'>Android ImageSpan  Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRTt83O2JTfpKuOhpG1CDTlYxSCx5uOzYXVakmgv3O-KF4IOTu1YHvhAPMVxbukii8PO0KbYVsi9Mv2wM1-ymbQw2Or5-DMOcuxCGZAtNGHj6q9hAOvrT2W8GiUmTk2TdldQ76ONitcwk/s1600/Android_ImageSpan_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRTt83O2JTfpKuOhpG1CDTlYxSCx5uOzYXVakmgv3O-KF4IOTu1YHvhAPMVxbukii8PO0KbYVsi9Mv2wM1-ymbQw2Or5-DMOcuxCGZAtNGHj6q9hAOvrT2W8GiUmTk2TdldQ76ONitcwk/s400/Android_ImageSpan_1.png&quot; /&gt;&lt;/a&gt;





&lt;/td&gt;
&lt;td&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5ab3cmGJx_x-LZvWFO_TSNVC3ihId5A0uASmh3DyMquCdIBL_4lgvfSAVoWfkv36XUAbmsXz7YqcC_GxSbGPTKRLWZXAx3JzBeduV5OJD3qONur20XfAXGM1lxMPNU_ensl973VdCQZU/s1600/Android_ImageSpan_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5ab3cmGJx_x-LZvWFO_TSNVC3ihId5A0uASmh3DyMquCdIBL_4lgvfSAVoWfkv36XUAbmsXz7YqcC_GxSbGPTKRLWZXAx3JzBeduV5OJD3qONur20XfAXGM1lxMPNU_ensl973VdCQZU/s400/Android_ImageSpan_2.png&quot; /&gt;&lt;/a&gt;




&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;b&gt;res/layout/main.xml :&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

&amp;lt;EditText 
        android:id=&quot;@+id/editText1&quot;
        android:layout_marginTop=&quot;10dp&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:minLines=&quot;6&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;@string/hello&quot; /&gt;
&amp;lt;TextView 
        android:id=&quot;@+id/txtview&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:textSize=&quot;25.0dp&quot;
        android:gravity=&quot;center&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;ImageSpan&quot; /&gt;
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;ImageSpanActivity.java:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class ImageSpanActivity extends Activity {
 private EditText ettxt;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ettxt = (EditText) this.findViewById(R.id.editText1);
        ettxt.setText(&quot;HelloWorld&quot;);
        
        Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);
  drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
    drawable.getIntrinsicHeight());
  SpannableString spannable = new SpannableString(getText()
    .toString() + &quot;[smile]&quot;);
  ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
  spannable.setSpan(span, getText().length(),
    getText().length() + &quot;[smile]&quot;.length(),
    Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
  setText(spannable);
    }
 private Editable getText() {
  return ettxt.getText();
 }

 private void setText(SpannableString spannalbe) {
  ettxt.setText(spannalbe);

 }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/AndroidImageSpan.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_ImageSpan_Example&quot; target=&quot;_blank&quot;&gt;AndroidImageSpan&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/2544810334337774673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-imagespan-example.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/2544810334337774673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/2544810334337774673'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-imagespan-example.html' title='Android ImageSpan  Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRTt83O2JTfpKuOhpG1CDTlYxSCx5uOzYXVakmgv3O-KF4IOTu1YHvhAPMVxbukii8PO0KbYVsi9Mv2wM1-ymbQw2Or5-DMOcuxCGZAtNGHj6q9hAOvrT2W8GiUmTk2TdldQ76ONitcwk/s72-c/Android_ImageSpan_1.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-7772171557342622437</id><published>2012-06-25T13:04:00.000-07:00</published><updated>2012-06-25T13:30:32.602-07:00</updated><title type='text'>Android InputFilter Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgf-aIlUwBl741XKiOmAIU6dplZrPH2q_QwQglqxYe3oRRcYCRevAvI1XoDOnLM4Y9_YlAxNOUJ5kudx2SpKhSWGGS6eJZTipGMICoZyLuMwvMz4troZJwWySM2mY2JKWttc1Meyx24ms/s1600/Android_InputFilter_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgf-aIlUwBl741XKiOmAIU6dplZrPH2q_QwQglqxYe3oRRcYCRevAvI1XoDOnLM4Y9_YlAxNOUJ5kudx2SpKhSWGGS6eJZTipGMICoZyLuMwvMz4troZJwWySM2mY2JKWttc1Meyx24ms/s400/Android_InputFilter_2.png&quot; /&gt;&lt;/a&gt;

&lt;/td&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNQ7ao7rEs-hPCjCrlbgh_H7O7-DI_e7s5ITs5sH-6LFIGZH7-TComuCFkTcIKDmBrgzApR6eJ4va9LapJYFoz-qVG1KhRx3yf8K1H4ef9pazwd1C6gzGR6HplFF5ZPmMysNkwL8UU6Cc/s1600/Android_InputFilter_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNQ7ao7rEs-hPCjCrlbgh_H7O7-DI_e7s5ITs5sH-6LFIGZH7-TComuCFkTcIKDmBrgzApR6eJ4va9LapJYFoz-qVG1KhRx3yf8K1H4ef9pazwd1C6gzGR6HplFF5ZPmMysNkwL8UU6Cc/s400/Android_InputFilter_1.png&quot; /&gt;&lt;/a&gt;


&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;b&gt;res/layout/main.xml :&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

    &amp;lt;EditText    
        android:id=&quot;@+id/edit_text&quot;  
        android:layout_marginTop=&quot;10dp&quot;    
        android:layout_width=&quot;fill_parent&quot;     
        android:layout_height=&quot;wrap_content&quot;    
       /&gt;  
    &amp;lt;Button
        android:id=&quot;@+id/btnId&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;Lock/Unlock&quot; /&gt;
&amp;lt;TextView 
        android:id=&quot;@+id/txtview&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:textSize=&quot;25.0dp&quot;
        android:gravity=&quot;center&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;InputFilter&quot; /&gt;
&amp;lt;/LinearLayout&gt;

&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;InputFilterActivity.java:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class InputFilterActivity extends Activity {

    private EditText editText;    
    private boolean value = false; 
    Button b;
    String str = &quot;Hello,Android!&quot;; 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        editText=(EditText)findViewById(R.id.edit_text);  
        editText.setText(&quot;EditText component&quot;);  
         b = (Button) findViewById(R.id.btnId);    
        b.setText(&quot;Lock&quot;);    
        b.setOnClickListener(new View.OnClickListener() {         
            @Override    
            public void onClick(View v) {    
                if (value) {    
                    value = false; 
                    b.setText(&quot;Lock&quot;);
                } else {    
                    value = true;  
                    b.setText(&quot;Unlock&quot;);
                }    
                lockUnlock(value);    
            }    
        });  
    }
    private void lockUnlock(boolean value) {    
        if (value) {    
            editText.setFilters(new InputFilter[] { new InputFilter() {    
                @Override    
                public CharSequence filter(CharSequence source, int start,    
                        int end, Spanned dest, int dstart, int dend) {    
                    return source.length() &lt; 1 ? dest.subSequence(dstart, dend)    
                                : &quot;&quot;;    
                }    
            } });    
        } else {    
            editText.setFilters(new InputFilter[] { new InputFilter() {    
                @Override    
                public CharSequence filter(CharSequence source, int start,    
                        int end, Spanned dest, int dstart, int dend) {    
                     return null;    
                }    
            } });    
        }    
    }    
}
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/AndroidInputFilter.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_InputFilter_Example&quot; target=&quot;_blank&quot;&gt;AndroidInputFilter&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/7772171557342622437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-inputfilter-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/7772171557342622437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/7772171557342622437'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-inputfilter-example.html' title='Android InputFilter Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgf-aIlUwBl741XKiOmAIU6dplZrPH2q_QwQglqxYe3oRRcYCRevAvI1XoDOnLM4Y9_YlAxNOUJ5kudx2SpKhSWGGS6eJZTipGMICoZyLuMwvMz4troZJwWySM2mY2JKWttc1Meyx24ms/s72-c/Android_InputFilter_2.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-3636234525797144807</id><published>2012-06-17T01:50:00.000-07:00</published><updated>2012-06-17T01:50:10.551-07:00</updated><title type='text'>Android: Toast Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
In Android,Toast is a notification message that usees to displays a message to the user and message  will disappear automatically after a certain period of time. 
Information can be simple text, it can be complex pictures and other content (shows a view) .
&lt;br/&gt;&lt;br/&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a alt=&quot;Android_Toast_Example&quot;  href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrhzIqMv6p74idWQnj4iLcDrnpWPO3qFVug3TJ-QEDUFVHK3TMgE357Trzpv1le3KJ8njTU54OI0P3E5Lbl545EiI4ZSHxSmYxGNg4BXKfBdlX-X7iMekjolnF4L-Q60kgbwybMQXcaVA/s1600/Android_Toast_Example.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrhzIqMv6p74idWQnj4iLcDrnpWPO3qFVug3TJ-QEDUFVHK3TMgE357Trzpv1le3KJ8njTU54OI0P3E5Lbl545EiI4ZSHxSmYxGNg4BXKfBdlX-X7iMekjolnF4L-Q60kgbwybMQXcaVA/s400/Android_Toast_Example.png&quot; alt=&quot;Android_Toast_Example&quot;  /&gt;&lt;/a&gt;




&lt;/td&gt;
&lt;td&gt;
&lt;a alt=&quot;Android_Toast_Example&quot;  href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZVFjc-iQumgDUZ2Y9b3-R86g273jkbd3n2tX58IcmXofBJR_VeJcHm0Y9R6GqTj_JxPF4TdPbUg3lOC5cNl8GWpg__h4QacSpPh-hsCOMiT6I9q193Oe9XXr_xEXYR0BDUVwxtjma7R0/s1600/Android_Custom_Toast_Example.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZVFjc-iQumgDUZ2Y9b3-R86g273jkbd3n2tX58IcmXofBJR_VeJcHm0Y9R6GqTj_JxPF4TdPbUg3lOC5cNl8GWpg__h4QacSpPh-hsCOMiT6I9q193Oe9XXr_xEXYR0BDUVwxtjma7R0/s400/Android_Custom_Toast_Example.png&quot; alt=&quot;Android_Toast_Example&quot;  /&gt;&lt;/a&gt;



&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;b&gt;main.xml:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

&amp;lt;Button android:id=&quot;@+id/button1&quot;
 android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;wrap_content&quot;
 android:text=&quot;Toast View&quot;
/&gt;
&amp;lt;Button android:id=&quot;@+id/button2&quot;
 android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;wrap_content&quot;
 android:text=&quot; Custom Toast View&quot;
/&gt;
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;

&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Add Layout for Toast my_toast.xml:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:background=&quot;@drawable/toast_border_one&quot; &gt;
    &amp;lt;ImageView 
        android:src=&quot;@drawable/warning&quot;
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        /&gt;
&amp;lt;TextView
    android:layout_width=&quot;wrap_content&quot; 
    android:id=&quot;@+id/TextViewInfo&quot;
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;Your error message here&quot;
    android:layout_gravity=&quot;center_vertical&quot;
     &gt;  
&amp;lt;/TextView&gt;
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;ToastActivity.java:&lt;/b&gt;
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class ToastActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
     Button btnone=(Button)findViewById(R.id.button1);
     btnone.setOnClickListener(btnoneListner);
     
     Button btntwo=(Button)findViewById(R.id.button2);
     btntwo.setOnClickListener(btntwoListner);
    }
    OnClickListener btnoneListner=new OnClickListener() {
  
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   Toast.makeText(ToastActivity.this,&quot;Your Text
           Here&quot;,Toast.LENGTH_LONG).show();
  }
 };
    OnClickListener btntwoListner=new OnClickListener() {
  
  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   showToast();
  }
 };
 public void showToast()
 {
       View toastRoot = getLayoutInflater()
                            .inflate(R.layout.my_toast, null);
       Toast toast=new Toast(getApplicationContext());
       toast.setView(toastRoot);
       toast.setGravity(Gravity.CENTER, 0, 40);
       toast.setDuration(Toast.LENGTH_LONG);
       TextView tv=(TextView)toastRoot.findViewById(R.id.TextViewInfo);
       tv.setText(&quot;Your error message here&quot;);
       toast.show();
 }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/CustomToast.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_Toast_Example&quot; target=&quot;_blank&quot;&gt;CustomToast&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/3636234525797144807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-toast-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/3636234525797144807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/3636234525797144807'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-toast-example.html' title='Android: Toast Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrhzIqMv6p74idWQnj4iLcDrnpWPO3qFVug3TJ-QEDUFVHK3TMgE357Trzpv1le3KJ8njTU54OI0P3E5Lbl545EiI4ZSHxSmYxGNg4BXKfBdlX-X7iMekjolnF4L-Q60kgbwybMQXcaVA/s72-c/Android_Toast_Example.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-8599475695981123470</id><published>2012-06-12T12:22:00.000-07:00</published><updated>2012-06-12T12:22:57.004-07:00</updated><title type='text'>Android Spinner Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
Spinner is a widget similar to a drop-down list for selecting items.&lt;/br&gt;&lt;/br&gt;
In this post, you&#39;ll create a simple spinner widget that displays a list of countries and implements OnItemSelectedListener When item is selected, 
a toast message will display the selected item.&lt;/br&gt;&lt;/br&gt;
&lt;b&gt;STEP 1:&lt;/b&gt; Start a new project named &lt;i&gt;AndroidSpinnerExample&lt;/i&gt;.
&lt;/br&gt;&lt;/br&gt;
&lt;b&gt;STEP 2:&lt;/b&gt; Open the &lt;i&gt;res\layout\main.xml&lt;/i&gt; file and insert the following code: &lt;/br&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:gravity=&quot;center&quot;
    android:orientation=&quot;vertical&quot; &gt;
 &amp;lt;Spinner 
 android:id=&quot;@+id/spinnertest&quot; 
 android:layout_width=&quot;wrap_content&quot; 
 android:layout_height=&quot;wrap_content&quot;
 android:entries=&quot;@+array/country_labels&quot;
 /&gt;
 &amp;lt;Button
 android:id = &quot;@+id/btn_OK&quot;
 android:layout_width = &quot;wrap_content&quot;
 android:layout_height = &quot;wrap_content&quot;
 android:text = &quot; OK &quot;
 /&gt;
 &amp;lt;TextView 
    android:id=&quot;@+id/txtselecteditem&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:text=&quot;Imran khan&#39;s Android&quot;
    android:textSize=&quot;30dp&quot;
    /&gt;
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a alt=&quot;Android_Spinner_Example_Imran_Khan_Android&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHFse2m_C6zetYlQAw9dHtCjkA5QxMohJmQTVjAcXlnQxSzcekawluM9owRvNsCMmiPa-LLalrLSzMEYtIeO7O3j_kN2IfmT6TAtHnrvf43S04_11GiWocwNwBbW_Xzw09xNSQFq4vPLs/s1600/Android_Spinner_Example_Imran_Khan_Android_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHFse2m_C6zetYlQAw9dHtCjkA5QxMohJmQTVjAcXlnQxSzcekawluM9owRvNsCMmiPa-LLalrLSzMEYtIeO7O3j_kN2IfmT6TAtHnrvf43S04_11GiWocwNwBbW_Xzw09xNSQFq4vPLs/s400/Android_Spinner_Example_Imran_Khan_Android_1.png&quot; alt=&quot;Android_Spinner_Example_Imran_Khan_Android&quot; /&gt;&lt;/a&gt;


&lt;/td&gt;
&lt;td&gt;
&lt;a alt=&quot;Android_Spinner_Example_Imran_Khan_Android&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJqxuNun-dLP1SKQKS7MyGq0yaF2n6gTMsWM-anNBx58MnIyLXx8L0PM0Cjt9Xfnoni-zlsQE4mZYNXRAbL5MFfjGYZP5tgdBo14WLK8WzheP8b1gMKkwJ0w4ZPFOQ2OHv4QldaLdIRLY/s1600/Android_Spinner_Example_Imran_Khan_Android_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; alt=&quot;Android_Spinner_Example_Imran_Khan_Android&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJqxuNun-dLP1SKQKS7MyGq0yaF2n6gTMsWM-anNBx58MnIyLXx8L0PM0Cjt9Xfnoni-zlsQE4mZYNXRAbL5MFfjGYZP5tgdBo14WLK8WzheP8b1gMKkwJ0w4ZPFOQ2OHv4QldaLdIRLY/s400/Android_Spinner_Example_Imran_Khan_Android_2.png&quot; /&gt;&lt;/a&gt;


&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;b&gt;STEP 3:&lt;/b&gt; Add new &lt;i&gt;arrays.xml&lt;/i&gt; in &lt;i&gt;res/values/&lt;/i&gt; and put following string array:
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;resources&gt;
&amp;lt;string-array name=&quot;country_labels&quot;&gt;
&amp;lt;item&gt;Afghanistan&amp;lt;/item&gt;
&amp;lt;item&gt;Bangladesh&amp;lt;/item&gt;
&amp;lt;item&gt;Bhutan&amp;lt;/item&gt;
&amp;lt;item&gt;Nepal&amp;lt;/item&gt;
&amp;lt;item&gt;Hindustan (Bharat)&amp;lt;/item&gt;
&amp;lt;item&gt;Iran&amp;lt;/item&gt;
&amp;lt;/string-array&gt;
&amp;lt;/resources&gt;
&lt;/pre&gt;
&lt;/br&gt;
&lt;b&gt;STEP 4:&lt;/b&gt; SpinnerActivity implements &lt;i&gt;OnItemSelectedListener &lt;/i&gt;to get selected item from Spinner as:
&lt;pre class=&quot;brush: java&quot;&gt;
public class SpinnerActivity extends Activity 
        implements OnItemSelectedListener {
 private Spinner Spinnerexp;
 private Button btn;
 private TextView txtview;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Spinnerexp = (Spinner)findViewById(R.id.spinnertest);
        btn = (Button)findViewById(R.id.btn_OK);
        txtview=(TextView)findViewById(R.id.txtselecteditem);
        btn.setOnClickListener(ocl);
        Spinnerexp.setOnItemSelectedListener(this);
    }
    private Button.OnClickListener ocl = new Button.OnClickListener(){
     public void onClick(View v){
     String choseValue = Spinnerexp.getSelectedItem().toString();
     Toast.makeText(SpinnerActivity.this, choseValue, 
        Toast.LENGTH_SHORT).show();
     }
     };
 @Override
 public void onItemSelected(AdapterView&lt;?&gt; arg0, 
          View arg1, int arg2,long arg3) {
  // Get Selected Text From Spinner
     String choseValue = Spinnerexp.getSelectedItem().toString();
     txtview.setText(choseValue);
 }
 @Override
 public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
  // TODO Auto-generated method stub
  
 }
}
&lt;/pre&gt;
&lt;/br&gt;
&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/AndroidSpinnerExample.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_Spinner_Example_Imran_Khan_Android&quot; target=&quot;_blank&quot;&gt;AndroidSpinnerExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/8599475695981123470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-spinner-example.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/8599475695981123470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/8599475695981123470'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-spinner-example.html' title='Android Spinner Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHFse2m_C6zetYlQAw9dHtCjkA5QxMohJmQTVjAcXlnQxSzcekawluM9owRvNsCMmiPa-LLalrLSzMEYtIeO7O3j_kN2IfmT6TAtHnrvf43S04_11GiWocwNwBbW_Xzw09xNSQFq4vPLs/s72-c/Android_Spinner_Example_Imran_Khan_Android_1.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-864482039656605136</id><published>2012-06-07T10:54:00.001-07:00</published><updated>2012-06-07T10:54:49.653-07:00</updated><title type='text'>Android GridView Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpjilorhymP1ytL6I8rELGwiV-3fhmtAIdAVAANulrY1SzBBNeMjsu9iLDrcOxuLfMRnvaBuY1ckFJuxP0K9FED0yJcGwcQ5L0WF0sDSPT3LCkQuWqcokBOPZD1UzOSZwdwj8DlAg389U/s1600/Android_GridView_Example_Imran_Khan_Android_01.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot; alt=&quot;Android_GridView_Example_Imran_Khan_Android&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpjilorhymP1ytL6I8rELGwiV-3fhmtAIdAVAANulrY1SzBBNeMjsu9iLDrcOxuLfMRnvaBuY1ckFJuxP0K9FED0yJcGwcQ5L0WF0sDSPT3LCkQuWqcokBOPZD1UzOSZwdwj8DlAg389U/s400/Android_GridView_Example_Imran_Khan_Android_01.png&quot; alt=&quot;Android_GridView_Example_Imran_Khan_Android&quot; /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;a alt=&quot;Android_GridView_Example_Imran_Khan_Android&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0FrWkjGyi0F3PBDuWwX-JY2SVCpCB5Anx3y09SvWaIvS31ze_Kd3ZzTgVx1h5DTGwMJW2gSiArq4lnzEyWc1se_iD-9xV9zu0JsfQLnShvTNcFQ1bblbgwVYjODQbwM9J3J2YnrBeILc/s1600/Android_GridView_Example_Imran_Khan_Android_02.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0FrWkjGyi0F3PBDuWwX-JY2SVCpCB5Anx3y09SvWaIvS31ze_Kd3ZzTgVx1h5DTGwMJW2gSiArq4lnzEyWc1se_iD-9xV9zu0JsfQLnShvTNcFQ1bblbgwVYjODQbwM9J3J2YnrBeILc/s400/Android_GridView_Example_Imran_Khan_Android_02.png&quot; alt=&quot;Android_GridView_Example_Imran_Khan_Android&quot; /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;b&gt;In &lt;i&gt;res/layout/main.xml&lt;/i&gt; layout add GridView  as&lt;/b&gt; :&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;GridView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;   
    android:id=&quot;@+id/grdview&quot;  
    android:paddingTop=&quot;20dp&quot;
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;fill_parent&quot;  
    android:numColumns=&quot;auto_fit&quot;  
    android:verticalSpacing=&quot;40dp&quot;  
    android:horizontalSpacing=&quot;30dp&quot;  
    android:columnWidth=&quot;90dp&quot;  
    android:stretchMode=&quot;columnWidth&quot;  
    android:gravity=&quot;center&quot;  
/&gt; 
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;In &lt;i&gt;res/layout/&lt;/i&gt; Create an gridviewitem.xml layout for GridView items   as&lt;/b&gt; :&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:paddingBottom=&quot;5dip&quot;
    android:layout_height=&quot;fill_parent&quot; &gt;
    
         &amp;lt;ImageView   
               android:layout_height=&quot;wrap_content&quot;   
               android:id=&quot;@+id/grditemimg&quot;   
               android:layout_width=&quot;wrap_content&quot;   
               android:layout_centerHorizontal=&quot;true&quot;&gt;   
         &amp;lt;/ImageView&gt;  
         
         &amp;lt;TextView   
               android:layout_width=&quot;wrap_content&quot;   
               android:layout_below=&quot;@+id/grditemimg&quot;   
               android:layout_height=&quot;wrap_content&quot;   
               android:text=&quot;TextView01&quot;   
               android:layout_centerHorizontal=&quot;true&quot;   
               android:id=&quot;@+id/grditemtxt&quot;&gt;  
         &amp;lt;/TextView&gt;

&amp;lt;/RelativeLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;In &lt;i&gt;GridViewActivity&lt;/i&gt; &lt;/b&gt; :&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public class GridViewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.
       FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        GridView gridview = (GridView) findViewById(R.id.grdview);  
        ArrayList&amp;lt;HashMap&amp;lt;String, Object&gt;&gt; lstImageItem =
             new ArrayList&amp;lt;HashMap&amp;lt;String, Object&gt;&gt;(); 

        HashMap&amp;lt;String,Object&gt; map = new HashMap&amp;lt;String,Object&gt;();
             map.put(&quot;itemimg&quot;, R.drawable.v01);
             map.put(&quot;itemtxt&quot;, &quot;Blogger&quot;);
             lstImageItem.add(map); 
             map = new HashMap&lt;String,Object&gt;();
             map.put(&quot;itemimg&quot;, R.drawable.v02);
             map.put(&quot;itemtxt&quot;, &quot;Facebook&quot;);
             lstImageItem.add(map); 
             map = new HashMap&lt;String,Object&gt;();
             map.put(&quot;itemimg&quot;, R.drawable.v03);
             map.put(&quot;itemtxt&quot;, &quot;Flickr&quot;);
             lstImageItem.add(map); 
             map = new HashMap&lt;String,Object&gt;();
             map.put(&quot;itemimg&quot;, R.drawable.v04);
             map.put(&quot;itemtxt&quot;, &quot;Hi5&quot;);
             lstImageItem.add(map); 
             map = new HashMap&lt;String,Object&gt;();
             map.put(&quot;itemimg&quot;, R.drawable.v05);
             map.put(&quot;itemtxt&quot;, &quot;Linkedin&quot;);
             lstImageItem.add(map); 
             map = new HashMap&lt;String,Object&gt;();
             map.put(&quot;itemimg&quot;, R.drawable.v06);
             map.put(&quot;itemtxt&quot;, &quot;Netvibes&quot;);
             lstImageItem.add(map); 
        SimpleAdapter saImageItems = new SimpleAdapter(this,
                lstImageItem,
                R.layout.gridviewitem,       
                new String[] {&quot;itemimg&quot;,&quot;itemtxt&quot;},   
                new int[] {R.id.grditemimg,R.id.grditemtxt});  
gridview.setAdapter(saImageItems);  

gridview.setOnItemClickListener(new ItemClickListener());
        
    }
    class  ItemClickListener implements OnItemClickListener  
    {  

 @SuppressWarnings(&quot;unchecked&quot;)
 @Override
 public void onItemClick(AdapterView&lt;?&gt; arg0, 
           View arg1, int arg2, long arg3) {
 // TODO Auto-generated method stub
 HashMap&amp;lt;String, Object&gt; item=
         (HashMap&amp;lt;String, Object&gt;) arg0.getItemAtPosition(arg2);  
      
 Toast.makeText(GridViewActivity.this, 
        (String)item.get(&quot;itemtxt&quot;), Toast.LENGTH_SHORT).show();
 setTitle((String)item.get(&quot;itemtxt&quot;));  
        } 
   }
}
&lt;/pre&gt;&lt;br/&gt;&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/GridViewExample.rar?attredirects=0&amp;d=1&quot; alt=&quot;Android_GridView_Example_Imran_Khan_Android&quot; target=&quot;_blank&quot;&gt;GridViewExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/864482039656605136/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-gridview-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/864482039656605136'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/864482039656605136'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-gridview-example.html' title='Android GridView Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpjilorhymP1ytL6I8rELGwiV-3fhmtAIdAVAANulrY1SzBBNeMjsu9iLDrcOxuLfMRnvaBuY1ckFJuxP0K9FED0yJcGwcQ5L0WF0sDSPT3LCkQuWqcokBOPZD1UzOSZwdwj8DlAg389U/s72-c/Android_GridView_Example_Imran_Khan_Android_01.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-6738100141613925958</id><published>2012-06-04T20:11:00.000-07:00</published><updated>2012-06-04T20:12:56.732-07:00</updated><title type='text'>Android SlidingDrawer Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiikj5aLXZAsh8pwX4v6L6ZY4LiSe5zQv8Cdzza6-fjmVgM3nDDQLE2Us46TnV39OslOYsRd0dBnHwPgcPnw-P6Z18CEPN8tmm8Qn4jBHMgphPeBhTv7loZ9sA7XWnNTkK5BFvtiRiTye0/s1600/Android_SlidingDrawer_Example_Imran_Khan_Android_11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiikj5aLXZAsh8pwX4v6L6ZY4LiSe5zQv8Cdzza6-fjmVgM3nDDQLE2Us46TnV39OslOYsRd0dBnHwPgcPnw-P6Z18CEPN8tmm8Qn4jBHMgphPeBhTv7loZ9sA7XWnNTkK5BFvtiRiTye0/s400/Android_SlidingDrawer_Example_Imran_Khan_Android_11.png&quot; /&gt;&lt;/a&gt;




&lt;/td&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMPYJW6BC-GgznBlG5s20zLZlCd6dngVpCK3p2W7IBT5UkuqQO2tlT3RS4wGRXWZUocYim47PyXr7wnMfQIvSvGM1-T-PuUpA09h8zlbSEnjRwNOdOHe7FMnlbSVd3iyVUWFAyasN9Lhc/s1600/Android_SlidingDrawer_Example_Imran_Khan_Android_12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMPYJW6BC-GgznBlG5s20zLZlCd6dngVpCK3p2W7IBT5UkuqQO2tlT3RS4wGRXWZUocYim47PyXr7wnMfQIvSvGM1-T-PuUpA09h8zlbSEnjRwNOdOHe7FMnlbSVd3iyVUWFAyasN9Lhc/s400/Android_SlidingDrawer_Example_Imran_Khan_Android_12.png&quot; /&gt;&lt;/a&gt;




&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;div&gt;
SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. SlidingDrawer can be used vertically or horizontally. A special widget composed of two children views: the handle, that the users drags, and the content, attached to the handle and dragged with it. SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for instance. The size of the SlidingDrawer defines how much space the content will occupy once slid out so SlidingDrawer should usually use match_parent for both its dimensions. Inside an XML layout, SlidingDrawer must define the id of the handle and of the content.&lt;br/&gt;
Two important methods  of SlidingDrawer :

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;&lt;a href=&quot;http://developer.android.com/reference/android/widget/SlidingDrawer.html&quot;&gt;void setOnDrawerCloseListener(SlidingDrawer.OnDrawerCloseListener onDrawerCloseListener)&lt;/a&gt;:&lt;/b&gt;&lt;br/&gt;
Sets the listener that receives a notification when the drawer becomes close.&lt;br/&gt;&lt;br/&gt;
&lt;/li&gt;
  &lt;li&gt;&lt;b&gt;&lt;a href=&quot;http://developer.android.com/reference/android/widget/SlidingDrawer.html&quot;&gt;void setOnDrawerOpenListener(SlidingDrawer.OnDrawerOpenListener onDrawerOpenListener)&lt;/a&gt;:&lt;/b&gt;&lt;br/&gt;
Sets the listener that receives a notification when the drawer becomes open.
&lt;/li&gt;
  
&lt;/ul&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;In &lt;i&gt;res/layout/main.xm&lt;/i&gt; layout add SlidingDrawer View as&lt;/b&gt; :&lt;/i&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;SlidingDrawer xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;  
    android:id=&quot;@+id/drawer&quot; 
    android:layout_width=&quot;fill_parent&quot;  
    android:layout_height=&quot;fill_parent&quot; 
    android:handle=&quot;@+id/handle&quot;  
    android:background=&quot;@drawable/a07&quot;
    android:content=&quot;@+id/content&quot;&gt;  
  
    &amp;lt;ImageView android:id=&quot;@id/handle&quot; 
        android:layout_width=&quot;wrap_content&quot;  
        android:layout_height=&quot;wrap_content&quot; 
        android:src=&quot;@drawable/arrow_up&quot;&gt;
    &amp;lt;/ImageView&gt;  
    &amp;lt;ListView android:id=&quot;@id/content&quot; 
        android:layout_width=&quot;fill_parent&quot;  
        android:layout_height=&quot;fill_parent&quot; 
        android:background=&quot;#ff00C0&quot;&gt;
    &amp;lt;/ListView&gt;  
  
&amp;lt;/SlidingDrawer&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt; In &lt;i&gt;SlidingDrawerActivity&lt;/i&gt; implements OnItemClickListener, OnDrawerOpenListener and OnDrawerCloseListener as:&lt;/b&gt;&lt;br/&gt;
&lt;pre class=&quot;brush:java&quot;&gt;
package com.imrankhanandroid.SlidingDrawerExp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SlidingDrawer;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;

public class SlidingDrawerActivity extends Activity implements 
OnItemClickListener,OnDrawerOpenListener,OnDrawerCloseListener {
    private SlidingDrawer drawer;  
    private ImageView handle;  
    private ListView content;  
    private String[] strcntycode={&quot;IN&quot;,&quot;US&quot;,&quot;UK&quot;,&quot;JAP&quot;,&quot;PK&quot;,&quot;CH&quot;};
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.
        FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        drawer = (SlidingDrawer) this.findViewById(R.id.drawer);  
        handle = (ImageView) this.findViewById(R.id.handle);  
        content = (ListView) this.findViewById(R.id.content);  
        content.setAdapter(new ArrayAdapter&lt;String&gt;(this,  
                android.R.layout.simple_list_item_1, strcntycode));
        content.setOnItemClickListener(this); 
        drawer.setOnDrawerOpenListener(this);  
        drawer.setOnDrawerCloseListener(this);  
    }

	@Override
	public void onItemClick(AdapterView&lt;?&gt; arg0, 
                    View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
        Toast.makeText(this, &quot;Clicked Position &quot; + (arg2 + 1)+&quot;Code is :&quot;
        +strcntycode[arg2],Toast.LENGTH_SHORT).show();  
	}

	@Override
	public void onDrawerOpened() {
		// TODO Auto-generated method stub
		handle.setImageResource(R.drawable.arrow_down);
	}

	@Override
	public void onDrawerClosed() {
		// TODO Auto-generated method stub
		handle.setImageResource(R.drawable.arrow_up);
	}
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/SlidingDrawerExample.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;SlidingDrawerExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/6738100141613925958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-slidingdrawer-example.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/6738100141613925958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/6738100141613925958'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-slidingdrawer-example.html' title='Android SlidingDrawer Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiikj5aLXZAsh8pwX4v6L6ZY4LiSe5zQv8Cdzza6-fjmVgM3nDDQLE2Us46TnV39OslOYsRd0dBnHwPgcPnw-P6Z18CEPN8tmm8Qn4jBHMgphPeBhTv7loZ9sA7XWnNTkK5BFvtiRiTye0/s72-c/Android_SlidingDrawer_Example_Imran_Khan_Android_11.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-2642809126375846494</id><published>2012-06-04T18:34:00.000-07:00</published><updated>2012-06-04T18:34:56.500-07:00</updated><title type='text'>Android ViewFlipper Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDogrnvdz-Pvka5LSFqi-Ulp6ebtgWOWxuDarHHlDX5sCbxpJJhyj2WK9vXmnoBTg2FvdvmFSm-xZme-HmczTzzw2bxYzsqxWQj4ZagXQm94mrUgzdMHNgw1GH406iBFaFH_BJCKZ1Spg/s1600/Android_ViewFlipper_Example_Imran_Khan_Android.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDogrnvdz-Pvka5LSFqi-Ulp6ebtgWOWxuDarHHlDX5sCbxpJJhyj2WK9vXmnoBTg2FvdvmFSm-xZme-HmczTzzw2bxYzsqxWQj4ZagXQm94mrUgzdMHNgw1GH406iBFaFH_BJCKZ1Spg/s400/Android_ViewFlipper_Example_Imran_Khan_Android.png&quot; /&gt;&lt;/a&gt;


&lt;/td&gt;
&lt;td&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjt1PmDPqwh13KtmzC0B2K_p9HoGuEKhxJEtKFr7_z4CltCh_p3kYx3tEyFEVDepg8Y2VKmwsUwdhJJ0ZlkFGdhTNzfhP6KMSkszMwSuS9BJVtUUCG8TI0fzRYuhjrDj1fva4-P8JewowA/s1600/Android_ViewFlipper_Example_Imran_Khan_Android_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjt1PmDPqwh13KtmzC0B2K_p9HoGuEKhxJEtKFr7_z4CltCh_p3kYx3tEyFEVDepg8Y2VKmwsUwdhJJ0ZlkFGdhTNzfhP6KMSkszMwSuS9BJVtUUCG8TI0fzRYuhjrDj1fva4-P8JewowA/s400/Android_ViewFlipper_Example_Imran_Khan_Android_1.png&quot; /&gt;&lt;/a&gt;


&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;b&gt;STEP 1:&lt;/b&gt; Creating a new project from&lt;i&gt; File-&gt;New-&gt;Android Project&lt;/i&gt; with ViewFlipperActivity Activity Name&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 2:&lt;/b&gt; Copy Image files to &lt;i&gt;res/drawable&lt;/i&gt; Folder&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 3:&lt;/b&gt; In &lt;i&gt;res/layout/main.xm&lt;/i&gt; layout add ViewFlipper as:&lt;/i&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

    &amp;lt;ViewFlipper  
        android:id=&quot;@+id/viewflipper&quot;  
        android:layout_width=&quot;fill_parent&quot;  
        android:layout_height=&quot;fill_parent&quot;/&gt;

&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 4:&lt;/b&gt; Create an &lt;i&gt;anim&lt;/i&gt; folder inside res and put xml for Transaction effect for Left In, Right In,Left Out and Right Out.&lt;/i&gt;&lt;br/&gt;

res/anim/push_left_in.xml:&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;set xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    &amp;lt;translate 
        android:fromXDelta=&quot;100%p&quot; 
        android:toXDelta=&quot;0&quot;  
        android:duration=&quot;500&quot; /&gt;  
    &amp;lt;alpha 
        android:fromAlpha=&quot;0.1&quot; 
        android:toAlpha=&quot;1.0&quot;  
        android:duration=&quot;500&quot; /&gt; 
&amp;lt;/set&gt;
&lt;/pre&gt;
&lt;br/&gt;
res/anim/push_left_out.xml:&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;set xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    &amp;lt;translate 
        android:fromXDelta=&quot;0&quot; 
        android:toXDelta=&quot;-100%p&quot;  
        android:duration=&quot;500&quot; /&gt;  
    &amp;lt;alpha 
        android:fromAlpha=&quot;1.0&quot; 
        android:toAlpha=&quot;0.1&quot;  
        android:duration=&quot;500&quot; /&gt; 
&amp;lt;/set&gt;
&lt;/pre&gt;
&lt;br/&gt;
res/anim/push_right_in.xml:&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;set xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    &amp;lt;translate 
      android:fromXDelta=&quot;-100%p&quot; 
      android:toXDelta=&quot;0&quot;  
      android:duration=&quot;500&quot; /&gt;  
    &amp;lt;alpha 
        android:fromAlpha=&quot;0.1&quot; 
        android:toAlpha=&quot;1.0&quot;  
        android:duration=&quot;500&quot; /&gt;  
&amp;lt;/set&gt;
&lt;/pre&gt;
&lt;br/&gt;
res/anim/push_right_out.xml:&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;set xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;  
    &amp;lt;translate 
        android:fromXDelta=&quot;0&quot; 
        android:toXDelta=&quot;100%p&quot;  
        android:duration=&quot;500&quot; /&gt;  
    &amp;lt;alpha 
        android:fromAlpha=&quot;1.0&quot; 
        android:toAlpha=&quot;0.1&quot;  
        android:duration=&quot;500&quot; /&gt;  
&amp;lt;/set&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 5:&lt;/b&gt; In &lt;i&gt;ViewFlipperActivity&lt;/i&gt; :&lt;/i&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package com.imrankhanandroid.ViewFlipperExp;

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ViewFlipper;

public class ViewFlipperActivity extends Activity implements  android.view.GestureDetector.OnGestureListener {
    /** Called when the activity is first created. */
    private int[] imageID = { 
    		R.drawable.a01, R.drawable.a02, 
    		R.drawable.a03, R.drawable.a04, 
    		R.drawable.a05, R.drawable.a06, 
    		R.drawable.a07, R.drawable.a08, 
    		R.drawable.a09, R.drawable.a010, 
    		R.drawable.a011
              };
    private ViewFlipper viewFlipper = null;  
    private GestureDetector gestureDetector = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper); 
        // gestureDetector Object is used to detect gesture events
        gestureDetector = new GestureDetector(this); 
        for (int i = 0; i &lt; imageID.length; i++)  
        { 
            ImageView image = new ImageView(this);  
            image.setImageResource(imageID[i]);  
            image.setScaleType(ImageView.ScaleType.FIT_XY);
            viewFlipper.addView(image, new LayoutParams(  
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        }
    }
	@Override
	public boolean onDown(MotionEvent arg0) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
			float arg3) {
		// TODO Auto-generated method stub
		if (arg0.getX() - arg1.getX() &gt; 120)  
        {  
            
            this.viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,  
                    R.anim.push_left_in));  
            this.viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,  
                    R.anim.push_left_out));  
            this.viewFlipper.showNext();  
            return true;  
        }
        else if (arg0.getX() - arg1.getX() &lt; -120)  
        {  
            this.viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,  
                    R.anim.push_right_in));  
            this.viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,  
                    R.anim.push_right_out));  
            this.viewFlipper.showPrevious();  
            return true;  
        }  
		return true;
	}
	@Override
	public void onLongPress(MotionEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
			float arg3) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public void onShowPress(MotionEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public boolean onSingleTapUp(MotionEvent arg0) {
		// TODO Auto-generated method stub
		return false;
	}
    @Override  
    public boolean onTouchEvent(MotionEvent event)  
    {  
        return this.gestureDetector.onTouchEvent(event);  
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/ViewFlipperExample.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;ViewFlipperExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/2642809126375846494/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-viewflipper-example.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/2642809126375846494'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/2642809126375846494'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-viewflipper-example.html' title='Android ViewFlipper Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDogrnvdz-Pvka5LSFqi-Ulp6ebtgWOWxuDarHHlDX5sCbxpJJhyj2WK9vXmnoBTg2FvdvmFSm-xZme-HmczTzzw2bxYzsqxWQj4ZagXQm94mrUgzdMHNgw1GH406iBFaFH_BJCKZ1Spg/s72-c/Android_ViewFlipper_Example_Imran_Khan_Android.png" height="72" width="72"/><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-960905775669011646</id><published>2012-06-03T11:52:00.000-07:00</published><updated>2012-06-03T11:53:35.122-07:00</updated><title type='text'>Android ImageSwitcher Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxiGtmIM2xd4p6HdGOj8W2-w-LXuiZ23kaPoRuQZMlk_9IFzWk32fpbbD3u_2FdvEMzDqZ8g-eUhxWMtCR5G0rlwNy8B-WNAdnMUkf4ubagdviMhDruPSTmbDtn3_jBKbquyqVYw1PAp8/s1600/Android_ImageSwitcher_Example_Imran_Khan_Android.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxiGtmIM2xd4p6HdGOj8W2-w-LXuiZ23kaPoRuQZMlk_9IFzWk32fpbbD3u_2FdvEMzDqZ8g-eUhxWMtCR5G0rlwNy8B-WNAdnMUkf4ubagdviMhDruPSTmbDtn3_jBKbquyqVYw1PAp8/s400/Android_ImageSwitcher_Example_Imran_Khan_Android.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPWJg59CRezA4n1nVlHpexfdY_tMbvHSV_9V4vd2OB8Yrrw7d2Hj1CHICbYhA4JoCAtOEvrFKQEmQ8gpOKYaZ4QztL8AZUBPcG5ccZktwyMDIg0wl58atMZ5WBl1We9mqUEGwfzncCmpI/s1600/Android_ImageSwitcher_Example_Imran_Khan_Android_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPWJg59CRezA4n1nVlHpexfdY_tMbvHSV_9V4vd2OB8Yrrw7d2Hj1CHICbYhA4JoCAtOEvrFKQEmQ8gpOKYaZ4QztL8AZUBPcG5ccZktwyMDIg0wl58atMZ5WBl1We9mqUEGwfzncCmpI/s400/Android_ImageSwitcher_Example_Imran_Khan_Android_2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;
&lt;b&gt;STEP 1:&lt;/b&gt; Creating a new project from&lt;i&gt; File-&gt;New-&gt;Android Project&lt;/i&gt; with ImageSwitcherExample Activity Name&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 2:&lt;/b&gt; Copy Image files to &lt;i&gt;res/drawable&lt;/i&gt; Folder&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 3:&lt;/b&gt; In &lt;i&gt;res/layout/main.xm&lt;/i&gt; layout add ImageSwitcher and Gallery View as:&lt;/i&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;RelativeLayout  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;
    &amp;lt;ImageSwitcher 
        android:layout_width=&quot;fill_parent&quot;  
        android:id=&quot;@+id/imgswitcher&quot; 
        android:layout_height=&quot;fill_parent&quot;  
        android:layout_alignParentTop=&quot;true&quot; 
        android:layout_alignParentLeft=&quot;true&quot; /&gt;    
    &amp;lt;Gallery android:id=&quot;@+id/galleryview&quot; 
        android:layout_width=&quot;fill_parent&quot;  
        android:layout_height=&quot;60dip&quot; 
        android:background=&quot;#55000000&quot;  
        android:layout_alignParentLeft=&quot;true&quot;  
        android:layout_alignParentBottom=&quot;true&quot; 
        android:gravity=&quot;center_vertical&quot;  
        android:spacing=&quot;16dip&quot; /&gt; 
&amp;lt;/RelativeLayout&gt;
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;STEP 4:&lt;/b&gt; Create an &lt;i&gt;ImageAdapter&lt;/i&gt; which extends &lt;i&gt;BaseAdapter &lt;/i&gt;as:&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package com.imrankhanandroid.Imageswitcherexp;

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

public class ImageAdapter extends BaseAdapter {

	private Context context;  
    public static Integer[] imageIDs={  
            R.drawable.a01,R.drawable.a02, 
            R.drawable.a03,R.drawable.a04, 
            R.drawable.a05,R.drawable.a06, 
            R.drawable.a07,R.drawable.a08, 
            R.drawable.a09,R.drawable.a010, 
            R.drawable.a011,R.drawable.a012, 
            R.drawable.a013
    };  
    public ImageAdapter(Context context){  
        this.context=context;  
    }  
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return imageIDs.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
		ImageView image=new ImageView(context);  
        image.setImageResource(imageIDs[position]);  
        image.setAdjustViewBounds(true);  
        image.setLayoutParams(new Gallery.LayoutParams(120,120));  
        image.setScaleType(ImageView.ScaleType.FIT_CENTER);  
        return image;  
	}

}
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;STEP 5:&lt;/b&gt; In &lt;i&gt;ImageSwitcherExampleActivity&lt;/i&gt; implements ViewFactory and OnItemSelectedListener. as:&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package com.imrankhanandroid.Imageswitcherexp;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ViewSwitcher.ViewFactory;

public class ImageSwitcherExampleActivity extends Activity 
    implements ViewFactory,OnItemSelectedListener {
    private ImageSwitcher mSwitcher;  
    private Gallery mGallery;  
    private int selectedTag = 0;  
    private int upX, downX;  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //Remove notification bar
        this.getWindow().setFlags(WindowManager.
        LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        setTitle(&quot;ImageSwitcher Example&quot;);  
        mSwitcher = (ImageSwitcher) findViewById(R.id.imgswitcher);  
        mSwitcher.setFactory(ImageSwitcherExampleActivity.this);  
        mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,  
                android.R.anim.fade_in));  
        mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,  
                android.R.anim.fade_out));  
        mSwitcher.setOnTouchListener(touchlistener);  
        mGallery = (Gallery) findViewById(R.id.galleryview);  
        mGallery.setAdapter(new ImageAdapter(ImageSwitcherExampleActivity.this));  
        mGallery.setOnItemSelectedListener(this);  
       
    }
    OnTouchListener touchlistener = new OnTouchListener() {

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			// TODO Auto-generated method stub
			if(event.getAction()==MotionEvent.ACTION_DOWN){
				downX=(int)event.getX();//Get Pressed Coordinates x
				return true;
			}
			else{
				if(event.getAction()==MotionEvent.ACTION_UP){
					upX=(int)event.getX();//get Released Coordinates x
					if(upX-downX&gt;100){ //From left to right drag
						  //if this is first drag to to tail
						if(mGallery.getSelectedItemPosition()==0){
							selectedTag=mGallery.getCount()-1;
						}
						else
						{
							selectedTag=mGallery.getSelectedItemPosition()-1;
						}
					}
					else{
						  if(downX-upX&gt;100){ //From right to left drag
							  if (mGallery.getSelectedItemPosition() == (mGallery  
			                            .getCount() - 1))  
			                        selectedTag = 0;  
			                    else  
			                        selectedTag = mGallery.getSelectedItemPosition() + 1;
						  }
					}
					return true;
				}
			}
			return false;
		} 
    	
    };
	@Override
	public View makeView() {
		// TODO Auto-generated method stub
		ImageView iv=new ImageView(this);
		iv.setBackgroundColor(0xFF000000);
		iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
		iv.setLayoutParams(new ImageSwitcher.LayoutParams(  
        LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
		return iv;
	}

	@Override
	public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		 mSwitcher.setImageResource(ImageAdapter.imageIDs[arg2]);  
	     selectedTag = arg2;  
	}

	@Override
	public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
		// TODO Auto-generated method stub
		
	}
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/ImageSwitcherExample.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;ImageSwitcherExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/960905775669011646/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-imageswitcher-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/960905775669011646'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/960905775669011646'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-imageswitcher-example.html' title='Android ImageSwitcher Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxiGtmIM2xd4p6HdGOj8W2-w-LXuiZ23kaPoRuQZMlk_9IFzWk32fpbbD3u_2FdvEMzDqZ8g-eUhxWMtCR5G0rlwNy8B-WNAdnMUkf4ubagdviMhDruPSTmbDtn3_jBKbquyqVYw1PAp8/s72-c/Android_ImageSwitcher_Example_Imran_Khan_Android.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-8630731775560648246</id><published>2012-06-03T08:01:00.000-07:00</published><updated>2012-06-03T08:04:39.883-07:00</updated><title type='text'>Android Gallery Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
Gallery is an internal element which can scroll horizontally and layout component of the currently selected child elements are positioned in the center of it.&lt;br/&gt;&lt;br/&gt;
&lt;div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv1rd8PSJwLAPceqd6IrllLJzUpD-cOUCoesgqwdR64CXAqH4HqoaNPwh681fGttaWIfxQvOEEuokaYrdRUv8gEZggr2xoWNxIJ2usgUYIIgPWTCYcQSz0zYSGloVuzsTOGheQV625prs/s1600/Android_Gallery_Example_Imran_Khan_Android.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv1rd8PSJwLAPceqd6IrllLJzUpD-cOUCoesgqwdR64CXAqH4HqoaNPwh681fGttaWIfxQvOEEuokaYrdRUv8gEZggr2xoWNxIJ2usgUYIIgPWTCYcQSz0zYSGloVuzsTOGheQV625prs/s400/Android_Gallery_Example_Imran_Khan_Android.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;/td&gt;
&lt;td&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwKsw1ozdd8TRUmth6gD6HuP1ZIvXnoeKX7vGTvbpba7oUJEgUxymwiCXNZ7DYpr-k8zk2vvFfqZ-8lqdSq7jWLngQO0sLDJGnNceGg78dJqlEfQDhuWWTyn5Hon8nBYe8qY0TcknMxxE/s1600/Android_Gallery_Example_Imran_Khan_Android_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwKsw1ozdd8TRUmth6gD6HuP1ZIvXnoeKX7vGTvbpba7oUJEgUxymwiCXNZ7DYpr-k8zk2vvFfqZ-8lqdSq7jWLngQO0sLDJGnNceGg78dJqlEfQDhuWWTyn5Hon8nBYe8qY0TcknMxxE/s400/Android_Gallery_Example_Imran_Khan_Android_2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 1:&lt;/b&gt; Creating a new project from&lt;i&gt; File-&gt;New-&gt;Android Project&lt;/i&gt; with Gallerydemo Activity Name&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 2:&lt;/b&gt; Copy Image files to &lt;i&gt;res/drawable&lt;/i&gt; Folder&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;STEP 3:&lt;/b&gt; In &lt;i&gt;res/layout/main.xm&lt;/i&gt; layout add ImageView and Gallery View as:&lt;/i&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt; 
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;FrameLayout  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

    &amp;lt;!-- ImageView for display image in background --&gt;  
   &amp;lt;ImageView  
        android:id=&quot;@+id/imgview&quot;  
        android:layout_width=&quot;fill_parent&quot;  
        android:layout_height=&quot;fill_parent&quot;  
        android:src=&quot;@drawable/a01&quot;  
         /&gt; 
         
         &amp;lt;!-- Gallery To show images Gallery  --&gt;  
        &amp;lt;Gallery xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;  
        android:id=&quot;@+id/galleryview&quot;  
        android:layout_width=&quot;fill_parent&quot;  
        android:layout_height=&quot;wrap_content&quot;  
        android:spacing=&quot;5dp&quot;  
        /&gt; 

&amp;lt;/FrameLayout &gt;
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;STEP 4:&lt;/b&gt; In &lt;i&gt;res/values add attrs.xml as:&lt;/i&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt; 
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;resources&gt;
   &amp;lt;declare-styleable name=&quot;HelloGallery&quot;&gt;  
        &amp;lt;attr name=&quot;android:galleryItemBackground&quot;/&gt;  
   &amp;lt;/declare-styleable&gt;
&amp;lt;/resources&gt;
&lt;/pre&gt;&lt;br/&gt;
&lt;b&gt;STEP 5:&lt;/b&gt; In &lt;i&gt;Gallerydemo Activity&lt;/i&gt; Create an ImageAdapter which extends &lt;i&gt;BaseAdapter &lt;/i&gt;as:&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package com.imrankhanandroid.Galleryexp;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Gallerydemo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      //Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        
        final ImageView imagevew = (ImageView)findViewById(R.id.imgview);  
        Gallery gallryview = (Gallery)findViewById(R.id.galleryview); 
        gallryview.setAdapter(new ImageAdapter(this));
        gallryview.setOnItemClickListener(new OnItemClickListener() {

	@Override
	public void onItemClick(AdapterView&lt;?&gt; parent,
            View view, int position,long id) {
		// TODO Auto-generated method stub
	        // The first few pictures show click 
		Toast.makeText(Gallerydemo.this, &quot;&quot; + position,  
		         Toast.LENGTH_LONG).show();  
		//Set the backgroundPart of theImageView
		imagevew.setImageResource(((ImageView) view).getId());
			}
		});
    }
    public class ImageAdapter extends BaseAdapter {

    	int mGalleryItemBackground;  
    	// Context object 
    	private Context mContext;  
    	// Picture array 
    	private Integer[] mImageIds ={
    			R.drawable.a01,R.drawable.a02,
    			R.drawable.a03,R.drawable.a04,
    			R.drawable.a05,R.drawable.a06,
    			R.drawable.a07,R.drawable.a08,
    			R.drawable.a09,R.drawable.a010,
    	};
    	// ImageAdapter Constructor 
    	public ImageAdapter(Context c) {
    	  this.mContext = c;
    	  //styleable resources
    	  TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
    	  mGalleryItemBackground = a.getResourceId(
    		R.styleable.HelloGallery_android_galleryItemBackground,0);
    		a.recycle();
    	}
    	// Get  number of items 
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mImageIds.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;
		}
		//Return  view 
		@Override
		public View getView(int position, View convertView, 
                   ViewGroup parent) {
			// TODO Auto-generated method stub
			ImageView iv = new ImageView(mContext); 
			iv.setImageResource(mImageIds[position]);
			iv.setId(mImageIds[position]);  
			iv.setLayoutParams(new Gallery.LayoutParams(120, 160));  
			iv.setScaleType(ImageView.ScaleType.FIT_XY);
			iv.setBackgroundResource(mGalleryItemBackground); 
			return iv;
		}
    }
    
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/GalleryExample.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;GalleryExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/8630731775560648246/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-gallery-example.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/8630731775560648246'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/8630731775560648246'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/android-gallery-example.html' title='Android Gallery Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv1rd8PSJwLAPceqd6IrllLJzUpD-cOUCoesgqwdR64CXAqH4HqoaNPwh681fGttaWIfxQvOEEuokaYrdRUv8gEZggr2xoWNxIJ2usgUYIIgPWTCYcQSz0zYSGloVuzsTOGheQV625prs/s72-c/Android_Gallery_Example_Imran_Khan_Android.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-870324227365580232</id><published>2012-06-02T13:31:00.000-07:00</published><updated>2012-06-03T01:47:44.508-07:00</updated><title type='text'>IntentService : Android</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;&lt;br/&gt;
&lt;i&gt;IntentService &lt;/i&gt;is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. 
Clients send requests through &lt;i&gt;startService(Intent)&lt;/i&gt; calls; the service is started as needed, 
handles each Intent in turn using a worker thread, and stops itself when it runs out of work.
&lt;/div&gt;
&lt;div&gt;&lt;br/&gt;
This &quot;work queue processor&quot; pattern is commonly used to offload tasks from an application&#39;s main thread. 
The &lt;i&gt;IntentService &lt;/i&gt;class exists to simplify this pattern and take care of the mechanics. 
To use it, extend &lt;i&gt;IntentService &lt;/i&gt;and implement &lt;i&gt;onHandleIntent(Intent)&lt;/i&gt;. 
IntentService will receive the Intents, launch a worker thread, and stop the service as appropriate.
&lt;/div&gt;
&lt;div&gt;&lt;br/&gt;
All requests are handled on a single worker thread - they may take as long as necessary (and will not block the application&#39;s main loop), 
but only one request will be processed at a time.
&lt;/div&gt;
&lt;div&gt;&lt;br/&gt;
&lt;i&gt;IntentService &lt;/i&gt;is a subclass of Service, and can handle asynchronous requests (with Intent).
 Service can be started when needed, and a separate thread to handle each Intent to, but after processing will be canceled.
&lt;/div&gt;
&lt;div&gt;&lt;br/&gt;
The work queue processor is generally used for the task from the application&#39;s main thread.
All requests will be handled in a separate thread, but not blocking the main thread of the application. And time to process a request.
&lt;/div&gt;
&lt;div&gt;

&lt;h4&gt;Service vs IntentService:&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;i&gt;Service &lt;/i&gt;class uses the application’s main thread, while &lt;i&gt;IntentService &lt;/i&gt;creates a worker thread and uses that thread to run the service.&lt;/li&gt;
  &lt;li&gt;&lt;i&gt;IntentService &lt;/i&gt;creates a queue that passes one intent at a time to &lt;i&gt;onHandleIntent()&lt;/i&gt;. Thus, implementing a multi-thread should be made by extending Service class directly.&lt;/li&gt;
  &lt;li&gt;&lt;i&gt;Service &lt;/i&gt;class needs a manual stop using &lt;i&gt;stopSelf()&lt;/i&gt;. Meanwhile, IntentService automatically stops itself when there is no intent in queue.&lt;/li&gt;
  &lt;li&gt;&lt;i&gt;IntentService &lt;/i&gt;implements &lt;i&gt;onBind()&lt;/i&gt; that returns null. This means that the &lt;i&gt;IntentService &lt;/i&gt;can not be bound by default.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;IntentService &lt;/i&gt;implements &lt;i&gt;onStartCommand()&lt;/i&gt; that sends Intent to queue and to &lt;i&gt;onHandleIntent()&lt;/i&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Service vs Thread vs AsyncTask:&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;i&gt;Threads &lt;/i&gt;or &lt;i&gt;Async &lt;/i&gt;task perform their tasks in a background thread thus they do not block the main thread, while a service performs it’s work in the main thread. so if a service is performing an intensive task such as calling a web service, it may block the main thread until it finishes. So for intensive tasks a service should run it’s work in a background thread.&lt;/li&gt;
  &lt;li&gt;A service runs in the same process of the application and keeps running until stopped by itself, stopped by the user or killed by the system if it needs memory.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;br /&gt;
IntentService of example:

&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;In IntentServiceActivity.java:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
package com.imrankhanandroid.Intentserviceexp;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class IntentServiceActivity extends Activity {
   
    private TextView text;  
    private Button btnStart;  
    private Button btnSendOther;  
    private MessageReceiver receiver ; 
   
    // Action 
      
    private static final String ACTION_RECV_MSG = 
          &quot;com.imrankhanandroid.intent.action.RECEIVE_MESSAGE&quot;;  
    private static final String ACTION_OTHER_MSG = 
          &quot;com.imrankhanandroid.intent.action.OTHER_MESSAGE&quot;; 
      
  
     // Message 
      
    private static final String MESSAGE_IN=&quot;message_input&quot;;  
    private static final String MESSAGE_OUT=&quot;message_output&quot;;  
    
    // Called when the activity is first created. 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        text=(TextView)findViewById(R.id.text);  
        text.setText(&quot;Preparation&quot;);  
        btnStart=(Button)findViewById(R.id.btnStart);  
        btnStart.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                // TODO Auto-generated method stub    
              Intent msgIntent = new Intent(IntentServiceActivity.this,   
                IntentServicetest.class);  
              text.setText(&quot;&quot;);
               msgIntent.putExtra(MESSAGE_IN, text.getText().toString());  
               startService(msgIntent);     
            }  
        });  
          
        btnSendOther=(Button)findViewById(R.id.btnSendOther);  
        btnSendOther.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                // TODO Auto-generated method stub  
            }  
        });  
        //Dynamic registration Receiver
        IntentFilter filter = new IntentFilter(ACTION_RECV_MSG);  
        filter.addCategory(Intent.CATEGORY_DEFAULT);  
        receiver = new MessageReceiver();  
        registerReceiver(receiver, filter);  
        IntentFilter filter2 = new IntentFilter(ACTION_OTHER_MSG);  
        filter2.addCategory(Intent.CATEGORY_DEFAULT);  
        receiver = new MessageReceiver();  
        registerReceiver(receiver, filter2);  
    }  
      //Broadcast to receive 
    public class MessageReceiver extends BroadcastReceiver {  
        @Override  
        public void onReceive(Context context, Intent intent) {   
           String message = intent.getStringExtra(MESSAGE_OUT);  
           text.setText(message);      
        Toast.makeText(context, &quot;message&quot;,Toast.LENGTH_SHORT).show();  
        }  
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;In IntentServicetest.java:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
package com.imrankhanandroid.Intentserviceexp;

import android.app.IntentService;
import android.content.Intent;
import android.os.SystemClock;
import android.text.format.DateFormat;
import android.util.Log;
 // IntentService
public class IntentServicetest extends IntentService {
    
    // Action 
     
    private static final String ACTION_RECV_MSG = 
    &quot;com.imrankhanandroid.intent.action.RECEIVE_MESSAGE&quot;;  
   
    // Message 
    
    private static final String MESSAGE_IN=&quot;message_input&quot;;  
    private static final String MESSAGE_OUT=&quot;message_output&quot;;  
 private final static String Tag=&quot;---IntentServicetest&quot;;
 
 public IntentServicetest() {
  // TODO Auto-generated constructor stub
  super(&quot;IntentServicetest&quot;);
  Log.d(Tag, &quot;Constructor&quot;);   
 }
    @Override  
    public void onDestroy() {   
        Log.d(Tag, &quot;onDestroy()&quot;);   
        super.onDestroy();   
    }   
    @Override  
    public void onStart(Intent intent, int startId) {   
        Log.d(Tag, &quot;onStart()&quot;);   
        super.onStart(intent, startId);   
    }   
    @Override  
    public int onStartCommand(Intent intent, int flags, int startId) {   
        Log.d(Tag, &quot;onStartCommand()&quot;);   
        return super.onStartCommand(intent, flags, startId);   
    }   
    @Override  
    public void setIntentRedelivery(boolean enabled) {   
        Log.d(Tag, &quot;setIntentRedelivery()&quot;);   
        super.setIntentRedelivery(enabled);   
    } 
 @Override
 protected void onHandleIntent(Intent intent) {
  // TODO Auto-generated method stub
  Log.d(Tag, &quot;IntentServicetest is onHandleIntent!&quot;);  
        String msgRecv = intent.getStringExtra(MESSAGE_IN); 
        Log.d(Tag, msgRecv);  
        for (int i = 0; i &lt; 5; i++) {  
            String resultTxt = msgRecv + &quot; &quot;  
                + DateFormat.format(&quot;MM/dd/yy hh:mm:ss&quot;, 
                        System.currentTimeMillis());  
            Intent broadcastIntent = new Intent();  
            broadcastIntent.setAction(ACTION_RECV_MSG);  
            broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);  
            broadcastIntent.putExtra(MESSAGE_OUT, resultTxt);  
            sendBroadcast(broadcastIntent);  
            SystemClock.sleep(1000);  
   } 
 }
}

&lt;/pre&gt;&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;In AndroidManifest.xml:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;com.imrankhanandroid.Intentserviceexp&quot;
    android:versionCode=&quot;1&quot;
    android:versionName=&quot;1.0&quot; &gt;
    &amp;lt;uses-sdk android:minSdkVersion=&quot;7&quot; /&gt;
    &amp;lt;application
        android:icon=&quot;@drawable/ic_launcher&quot;
        android:label=&quot;@string/app_name&quot; &gt;
        &amp;lt;activity
            android:label=&quot;@string/app_name&quot;
            android:name=&quot;.IntentServiceActivity&quot; &gt;
            &amp;lt;intent-filter &gt;
                &amp;lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                &amp;lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &amp;lt;/intent-filter&gt;
        &amp;lt;/activity&gt;
         &amp;lt;service android:name=&quot;.IntentServicetest&quot;&gt;&amp;lt;/service&gt;  
    &amp;lt;/application&gt;
&amp;lt;/manifest&gt;
&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuKFo3KyRh8WS1WTteoZ2_0HSvQAppmQELdyIYsrEs2b8dovQ0YZEWSzFRNml3cQYEFZvvAdAtpS3dPf6Hoh9Bt5DZVIBw7KCYx0hp9lAKN-nbhWDFlnT-Ql-Y9y2ay7ftJ3h8JW_fqug/s1600/Intent_Service_Example.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuKFo3KyRh8WS1WTteoZ2_0HSvQAppmQELdyIYsrEs2b8dovQ0YZEWSzFRNml3cQYEFZvvAdAtpS3dPf6Hoh9Bt5DZVIBw7KCYx0hp9lAKN-nbhWDFlnT-Ql-Y9y2ay7ftJ3h8JW_fqug/s400/Intent_Service_Example.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;br/&gt;&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;In main.xml:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

&amp;lt;TextView    
    android:id=&quot;@+id/text&quot;  
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:textSize=&quot;30sp&quot;  
    android:textColor=&quot;#FF0000&quot;  
    android:text=&quot;@string/hello&quot;  
    /&gt;  
      
 &amp;lt;Button  
    android:id=&quot;@+id/btnStart&quot;  
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Start&quot;  
 /&gt;  
   
 &amp;lt;Button  
    android:id=&quot;@+id/btnSendOther&quot;  
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;SendOtherBroadcast&quot;  
 /&gt;  

&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/IntentServiceExample.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;IntentServiceExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/870324227365580232/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/intentservice-android.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/870324227365580232'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/870324227365580232'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/intentservice-android.html' title='IntentService : Android'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuKFo3KyRh8WS1WTteoZ2_0HSvQAppmQELdyIYsrEs2b8dovQ0YZEWSzFRNml3cQYEFZvvAdAtpS3dPf6Hoh9Bt5DZVIBw7KCYx0hp9lAKN-nbhWDFlnT-Ql-Y9y2ay7ftJ3h8JW_fqug/s72-c/Intent_Service_Example.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-370774610961969818</id><published>2012-05-30T10:28:00.000-07:00</published><updated>2012-05-30T10:28:56.359-07:00</updated><title type='text'>Pass Data Between Activities in Android?: Part 4</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br/&gt;
&lt;div style=&#39;padding-left:5px;&#39;&gt;In Android, we can inherit the Application class to achieve application-level global variables, 
this method of global variables is relatively static class more secure,
 and will be released until after the application&#39;s  All Activities destroy out.&lt;/div&gt;
&lt;div style=&#39;padding-left:5px;&#39;&gt; &lt;br/&gt;In the Activity, we can use getApplication() method to obtain the Application, it is 
 representative of the class of our application, it can get the theme of the current application, the content in the resource file, 
 this class is more flexible a feature can we have inherited, to add our own global properties.&lt;/div&gt;
&lt;div style=&#39;padding-left:5px;&#39;&gt;&lt;br/&gt; All the Activity of the same application can take the value of these global variables, in other words, 
 we change the value of these global variables in an Activity, 
 then in the same value will change in an application Activity. The following example details the application steps:&lt;/div&gt;
&lt;div style=&#39;padding-left:5px;&#39;&gt;&lt;br/&gt; 
 &lt;b&gt;STEP 1::&lt;/b&gt; Write Application Subclass&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
     public class MyApplication extends Application {  
     
        //Variable we want to share to All Activities in Appliction
      private static final String NAME = &quot;MyApplication&quot;; 
            private String name;  
              
            @Override 
            public void onCreate() {  
                    super.onCreate();  
                    setName(NAME); //Initialize global variables 
            }  
            //Getter Method
            public String getName() {    
                    return name;  
            }  
            //Setter Method
            public void setName(String name) {  
                    this.name = name;  
            }  
       
    } 
&lt;/pre&gt;&lt;br/&gt;&lt;br/&gt;
&lt;b&gt; STEP 2:&lt;/b&gt; In the Manifest.xml Register MyApplication as:&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&lt;br /&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;  
&amp;lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; 
      package=&quot;com.hisoft.app&quot; 
      android:versionCode=&quot;1&quot; 
      android:versionName=&quot;1.0&quot;&gt;  
    &amp;lt;application android:icon=&quot;@drawable/icon&quot; 
                 android:name=&quot;.MyApplication&quot;&gt;
        &amp;lt;activity android:name=&quot;.MyFirstActivity&quot; 
                  android:label=&quot;@string/app_name&quot;&gt;  
          &lt;intent-filter&gt;  
            &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;  
            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;  
          &lt;/intent-filter&gt;  
        &lt;/activity&gt;  
        &lt;activity android:name=&quot;.MySecondActivity&quot;&gt;&lt;/activity&gt;  
    &lt;/application&gt;  
    &lt;uses-sdk android:minSdkVersion=&quot;8&quot; /&gt;  
&lt;/manifest&gt;
&lt;/pre&gt;&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 3:&lt;/b&gt; In the MyFirstActivity :&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
     public class MyFirstActivity extends Activity {  
         
        private MyApplication app;  
              
        @Override 
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.main);  
            app = (MyApplication)getApplication();  //Get  Application
            //Access global value
            Log.e(&quot;MyFirstActivityOriginal&quot;, app.getName());  
            app.setName(&quot;Android Android&quot;); //Set global value
            Log.e(&quot;MyFirstActivityChanged&quot;, app.getName());
            Intent intent = new Intent(); 
            intent.setClass(this, MySecondActivity.class);  
            startActivity(intent);  
        }  
    } 
&lt;/pre&gt;&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;STEP 4:&lt;/b&gt; In the MySecondActivity :
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
    public class MySecondActivity extends Activity {  
     
            private MyApplication app;  
              
            @Override 
            protected void onCreate(Bundle savedInstanceState) {  
                    super.onCreate(savedInstanceState);  
                    setContentView(R.layout.main);  
                    //Get  Application
                    app = (MyApplication)getApplication();  
                    //Access global value
                    Log.e(&quot;MySecondActivity&quot;, app.getName()); 
            }          
    } 
&lt;/pre&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEJTAR0VSUh01Lbxe3HP-05c2mDU_Ufpo4AaNdI9VWBDrt1dhrpBQnwkO7U1QuGGIYNG1voogwvP2R9rxijL2C30pXpYguL5lqs1aOF-JUs0lttgfanJrxmBcFinXtnXcalztwuZv_vgs/s1600/Android_Application_class_send_data.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEJTAR0VSUh01Lbxe3HP-05c2mDU_Ufpo4AaNdI9VWBDrt1dhrpBQnwkO7U1QuGGIYNG1voogwvP2R9rxijL2C30pXpYguL5lqs1aOF-JUs0lttgfanJrxmBcFinXtnXcalztwuZv_vgs/s400/Android_Application_class_send_data.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;br/&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/Applicationclass.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;Applicationclass&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/370774610961969818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-data-between-activities-in-android_30.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/370774610961969818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/370774610961969818'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-data-between-activities-in-android_30.html' title='Pass Data Between Activities in Android?: Part 4'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEJTAR0VSUh01Lbxe3HP-05c2mDU_Ufpo4AaNdI9VWBDrt1dhrpBQnwkO7U1QuGGIYNG1voogwvP2R9rxijL2C30pXpYguL5lqs1aOF-JUs0lttgfanJrxmBcFinXtnXcalztwuZv_vgs/s72-c/Android_Application_class_send_data.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-151514579756404957</id><published>2012-05-29T13:20:00.000-07:00</published><updated>2012-05-29T13:20:09.994-07:00</updated><title type='text'>Pass Data Between Activities in Android?: Part 3</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&amp;nbsp;You can Pass Data Between Activities using android.os.Bundle object which encapsulates data as key-value pairs.
&lt;br/&gt;&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;In SenderActivity.java Activtiy &lt;/b&gt;&lt;/i&gt;:
&lt;br/&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
 //Create new Intent Object, and specify class
        Intent intent = new Intent();  
        intent.setClass(SenderActivity.this,Receiveractivity.class);
          
        //new Bundle Object, and put data in bundle object 
        Bundle bundle = new Bundle();  
        bundle.putString(&quot;senddata&quot;,&quot;This is From SenderActivity.class&quot;);   
        
        //Put Bundle object i.e bundle in intent
        intent.putExtras(bundle);  
        
        //Call startActivity to start new Activity 
        SenderActivity.this.startActivity(intent);
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEt3-skx_81irH9jyOXmjLuppvZQRlxky6UqsD5mPojs15vEf32YRXzuNdtIzFbYpNgO0n2wloPHimzxFjUqeJkA3vn8j6SgOfrV1DvZ9cURJgXLO1ueDWeeQmDcGv-cHgE6LqET7qpqA/s1600/Send_Data_Using_Bundle.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEt3-skx_81irH9jyOXmjLuppvZQRlxky6UqsD5mPojs15vEf32YRXzuNdtIzFbYpNgO0n2wloPHimzxFjUqeJkA3vn8j6SgOfrV1DvZ9cURJgXLO1ueDWeeQmDcGv-cHgE6LqET7qpqA/s400/Send_Data_Using_Bundle.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;br/&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;In SenderActivity.java Activtiy&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
         //Intent To obtain the  bundle object from SenderActivity 
         Bundle bundle = this.getIntent().getExtras();  
      
   if(bundle !=null)
   {
           //ObtainBundleData in the object 
     String strdata = bundle.getString(&quot;senddata&quot;); 
      //Do something here if data  received
    }
    else
    {
      //Do something here if data not received
    }
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6wWdLWUvHemVG4HmPrJwQnY06Jrhkwq9aXTMYNR97HOXNzgHri08TM2FvHa9tu9INEeg6QziWXAoEr8j8aYfcxVn0mnsQP3bgEUW0NtwQFZat-O1LuR-G4Jy6Qs3KhPYaCcXQO5ESJPk/s1600/Send_Data_Using_Bundle_obj.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6wWdLWUvHemVG4HmPrJwQnY06Jrhkwq9aXTMYNR97HOXNzgHri08TM2FvHa9tu9INEeg6QziWXAoEr8j8aYfcxVn0mnsQP3bgEUW0NtwQFZat-O1LuR-G4Jy6Qs3KhPYaCcXQO5ESJPk/s400/Send_Data_Using_Bundle_obj.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/Intentpassdata_using_bundle.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;Intentpassdata_using_bundle&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/151514579756404957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-data-between-activities-in-android_29.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/151514579756404957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/151514579756404957'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-data-between-activities-in-android_29.html' title='Pass Data Between Activities in Android?: Part 3'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEt3-skx_81irH9jyOXmjLuppvZQRlxky6UqsD5mPojs15vEf32YRXzuNdtIzFbYpNgO0n2wloPHimzxFjUqeJkA3vn8j6SgOfrV1DvZ9cURJgXLO1ueDWeeQmDcGv-cHgE6LqET7qpqA/s72-c/Send_Data_Using_Bundle.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-4155605020836371024</id><published>2012-05-28T12:44:00.000-07:00</published><updated>2012-05-28T12:44:33.105-07:00</updated><title type='text'>Pass Data Between Activities in Android?: Part 2</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&amp;nbsp;You can pass data between to Activities using &lt;b&gt;Intent&lt;/b&gt;.Example:&lt;br/&gt;&lt;br/&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;In Activtiy SenderActivity.java&lt;/b&gt;&lt;/i&gt;:
&lt;br/&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
//Create new Intent Object, and specify class
Intent intent = new Intent();  
intent.setClass(SenderActivity.this,Receiveractivity.class);

//Set your data using putExtra method which take 
//any key and value which we want to send 
intent.putExtra(&quot;senddata&quot;,&quot;This is From SenderActivity.class&quot;);  

//Use startActivity or startActivityForResult for Starting New Activity
SenderActivity.this.startActivity(intent); 

&lt;/pre&gt;
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGYau3-oibSmJIRILG2mxVtMwdc0Qd88Fz1qPkIneVUnYO8Ta-itM75BlZFKBl46BoWZh9oAhOanJF47TACs5Nf4OGDY04gLvyAryOH-vxs-A1B7PKy6uezGy2ohckhLzH5JOWuoqlGUY/s1600/Pass_Data_Between_Activities.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGYau3-oibSmJIRILG2mxVtMwdc0Qd88Fz1qPkIneVUnYO8Ta-itM75BlZFKBl46BoWZh9oAhOanJF47TACs5Nf4OGDY04gLvyAryOH-vxs-A1B7PKy6uezGy2ohckhLzH5JOWuoqlGUY/s400/Pass_Data_Between_Activities.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;In Activtiy SenderActivity.java&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
      //obtain  Intent Object send  from SenderActivity
        Intent intent = this.getIntent();

        /* Obtain String from Intent  */
        if(intent !=null)
        {
           String strdata = intent.getExtras().getString(&quot;senddata&quot;);
          // DO SOMETHING HERE
        }
        else
        {
          // DO SOMETHING HERE
        }

&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2sjcFI7tgChrA0UXz0Uy7aMefRH7qGAHH2bCCBlOcrsI4c1iMdm5Ukd487XxtetDjOP6cM7EKhHqx5YMW5RnRbR-dFuQyC1FYa6E20s1j33saN_SuX8GlbbEzKnvL-pSZoDp2_goX9wU/s1600/Pass_Data_Between_Activities_Intent.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2sjcFI7tgChrA0UXz0Uy7aMefRH7qGAHH2bCCBlOcrsI4c1iMdm5Ukd487XxtetDjOP6cM7EKhHqx5YMW5RnRbR-dFuQyC1FYa6E20s1j33saN_SuX8GlbbEzKnvL-pSZoDp2_goX9wU/s400/Pass_Data_Between_Activities_Intent.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;br /&gt;&lt;br /&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/Intentpassdata.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;Intentpassdata&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/4155605020836371024/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-data-between-activities-in-android_28.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/4155605020836371024'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/4155605020836371024'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-data-between-activities-in-android_28.html' title='Pass Data Between Activities in Android?: Part 2'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGYau3-oibSmJIRILG2mxVtMwdc0Qd88Fz1qPkIneVUnYO8Ta-itM75BlZFKBl46BoWZh9oAhOanJF47TACs5Nf4OGDY04gLvyAryOH-vxs-A1B7PKy6uezGy2ohckhLzH5JOWuoqlGUY/s72-c/Pass_Data_Between_Activities.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-7823674077776845010</id><published>2012-05-27T04:01:00.000-07:00</published><updated>2012-05-27T04:04:00.677-07:00</updated><title type='text'>Pass Data Between Activities in Android? : Part 1</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br/&gt;
&amp;nbsp;There are two data types available in Java/Android:&lt;br/&gt;

&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;Primitive Data Types :&lt;/b&gt;&lt;/i&gt;&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;byte,&amp;nbsp;int,&amp;nbsp;long,&amp;nbsp;float,&amp;nbsp;boolean...&lt;br/&gt;

&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;Reference/Object Data Types :&lt;/b&gt;&lt;/i&gt;&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;String,Class objects, and various type of array variables come under reference data type.&lt;br/&gt;&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSN_J3ZgLHTaDIGTkhDItif33T1RWej3H3R8A9sLVFmeHv7_OpD7U2Xo_Sk4LnuHH2-cEUjttUqmnZOp5Kojo5HbeYTkzMd3Ag_Uao4vRSeG-zZ3GQ66zuW4s7mCwj__o4-xN2dD7mISY/s1600/DataTypes+in+andrid.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;237&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSN_J3ZgLHTaDIGTkhDItif33T1RWej3H3R8A9sLVFmeHv7_OpD7U2Xo_Sk4LnuHH2-cEUjttUqmnZOp5Kojo5HbeYTkzMd3Ag_Uao4vRSeG-zZ3GQ66zuW4s7mCwj__o4-xN2dD7mISY/s400/DataTypes+in+andrid.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;




&lt;br /&gt;
&lt;div style=&#39;padding-left:5px;&#39;&gt;
Way of passing data Between Application&#39;s Components :&lt;br/&gt;
&lt;ol style=&#39;font-weight:bold;&#39;&gt;
&lt;li&gt;&lt;span style=&#39;font-weight:normal;&#39;&gt;By Using Intent&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span  style=&#39;font-weight:normal;&#39;&gt;By Using Bundle and Intent&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&#39;font-weight:normal;&#39;&gt;By Using Appliction Class&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&#39;font-weight:normal;&#39;&gt;By Using Static Class&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;  
&lt;/div&gt;
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCMFmv-9rBnf4_9pFudPVoG_sxh61xWVjSka3tAyCW_VlcvCSWW6SsGMyHXvJw9PBWj4L0d-FcLeFAFTSSw6M6OyP3GotLrd3xJgxsvnwm0QiJ-D5ow4PGUXemTyOD5eseKKPU3zIv8RA/s1600/Wayof+passing+data+between+activities.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;148&quot; width=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCMFmv-9rBnf4_9pFudPVoG_sxh61xWVjSka3tAyCW_VlcvCSWW6SsGMyHXvJw9PBWj4L0d-FcLeFAFTSSw6M6OyP3GotLrd3xJgxsvnwm0QiJ-D5ow4PGUXemTyOD5eseKKPU3zIv8RA/s400/Wayof+passing+data+between+activities.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;




&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/7823674077776845010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-data-between-activities-in-android.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/7823674077776845010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/7823674077776845010'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-data-between-activities-in-android.html' title='Pass Data Between Activities in Android? : Part 1'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSN_J3ZgLHTaDIGTkhDItif33T1RWej3H3R8A9sLVFmeHv7_OpD7U2Xo_Sk4LnuHH2-cEUjttUqmnZOp5Kojo5HbeYTkzMd3Ag_Uao4vRSeG-zZ3GQ66zuW4s7mCwj__o4-xN2dD7mISY/s72-c/DataTypes+in+andrid.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-8706799966435613475</id><published>2012-05-26T02:20:00.000-07:00</published><updated>2012-06-03T02:21:19.668-07:00</updated><title type='text'>Pass Custom Object Using Parcelable: Android</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;&lt;br/&gt;
Parcelable is an Android specific interface where you implement the serialization yourself. 
It was created to be far more efficient that Serializable, and to get around some problems with the default Java serialization scheme.
&lt;br/&gt;
Serialization in Java is far too slow to satisfy Android’s interprocess-communication requirements.
The Parcelable approach requires that you explicitly serialize the members of your class, but in the end, you get a much faster serialization of your objects.
&lt;br/&gt;
&lt;b&gt;The writeToParcel Method:&lt;/b&gt;&lt;br/&gt;
The writeToParcel method is implemented quite easy as well. The Parcel interface contains methods to write primitve java types such as string, int, etc. We can use these methods to store the object state within the parcel.
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public void writeToParcel(Parcel outParcel, int flags) {
//Write data to Parcel
outParcel.writeString(message);
.....
}&lt;/pre&gt;&lt;br/&gt;
For the demarshalling, we need to remember the sequence in which we have stored the fields in the parcel.
&lt;br/&gt;
&lt;b&gt;The Parcelable.Creator CREATOR field:&lt;/b&gt;&lt;br/&gt;
The CREATOR field is required for the demarshalling. As previously described, the Parcelable.Creator interface requires us to implement two methods:
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
public static final Parcelable.Creator&lt;YOUR_CLASS_NAME&gt; 
CREATOR = new Parcelable.Creator&lt;YOUR_CLASS_NAME&gt;() {
@Override
public YOUR_CLASS_NAME createFromParcel(Parcel in) {
From ParcelTo read data,Return YOUR_CLASS_NAME Object 
String message = in.readString();
.....
return new YOUR_CLASS_NAME(Params...); //YOUR_CLASS_NAME constructor
}&lt;/pre&gt;&lt;br/&gt;
During the createFromParcel method we use the read methods which are provided in the Parcel to extract our state information.
In the end we create a new class object with the corresponding state.&lt;br/&gt;&lt;br/&gt;


Example Pass data by implemeting Parcelable interface:
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;  Car.java implemeting Parcelable interface:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package com.imrankhanandroid.PassdatausingParcelable;
import android.os.Parcel;
import android.os.Parcelable;

public class Car implements Parcelable {

    private String CarName;  
    private String companyName;  
    private int contactNum;
    public String getCarName() {  
        return CarName;  
    }  
    public void setCarName(String CarName) {  
        this.CarName = CarName;  
    }  
    public String getCompanyName() {  
        return companyName;  
    }  
    public void setCompanyName(String companyName) {  
        this.companyName = companyName;  
    }  
    public int getContactNum() {  
        return contactNum;  
    }  
    public void setcontactNum(int contactNum) {  
        this.contactNum = contactNum;  
    }  
    public static final Parcelable.Creator&lt;Car&gt; CREATOR =new Creator&lt;Car&gt;() {

  @Override
  public Car createFromParcel(Parcel source) {
   // TODO Auto-generated method stub
   Car mCar=new Car();
   mCar.CarName=source.readString();
   mCar.companyName=source.readString();
   mCar.contactNum=source.readInt();
   return mCar;
  }

  @Override
  public Car[] newArray(int size) {
   // TODO Auto-generated method stub
   return new Car[size];
  }
 };
 @Override
 public int describeContents() {
  // TODO Auto-generated method stub
  return 0;
 }

 @Override
 public void writeToParcel(Parcel parcel, int flags) {
  // TODO Auto-generated method stub
  parcel.writeString(CarName);
  parcel.writeString(companyName);
  parcel.writeInt(contactNum);
 }

}
&lt;/pre&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;  ObjectSenderActivity.java  Activity:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package com.imrankhanandroid.PassdatausingParcelable;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ObjectSenderActivity extends Activity {
 private Button sButton;  
    public  final static String PAR_KEY = &quot;com.imrankhanandroid.PassdatausingParcelable.par&quot;;  

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sButton = (Button)findViewById(R.id.btnsend); 
        sButton.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    PacelableMethod();
   }
  });
    }
  //PacelablePassing an object method
    public void PacelableMethod(){  
        Car mCar = new Car();  
        mCar.setCarName(&quot;jaguar xf sedan&quot;);  
        mCar.setCompanyName(&quot;jaguar&quot;);  
        mCar.setcontactNum(123456789);  
        Intent mIntent = new Intent(this,ObjectReceiverActivity.class);  
        Bundle mBundle = new Bundle();  
        mBundle.putParcelable(PAR_KEY, mCar);  
        mIntent.putExtras(mBundle);  
          
        startActivity(mIntent);  
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;  ObjectReceiverActivity.java  Activity:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
package com.imrankhanandroid.PassdatausingParcelable;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;


public class ObjectReceiverActivity extends Activity {
 TextView txtview;
  /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.maintwo);
       //Get person object from Intent deliver to ObjectReceiverActivity
       Car mCar = (Car)getIntent().getParcelableExtra(ObjectSenderActivity.PAR_KEY);
       txtview=(TextView)findViewById(R.id.txtrev);
       txtview.append(Html.fromHtml(&quot;&lt;br/&gt;Car Name :&quot;+mCar.getCarName()
         +&quot;&lt;br/&gt;Company Name :&quot;+mCar.getCompanyName()
       +&quot;&lt;br/&gt;Contact Num :&quot;+mCar.getContactNum()  
       ));
   }
}
&lt;/pre&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;  src/layout/main.xml:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

&amp;lt;TextView    
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Welcome to Imran Khan&#39;s Blog.&quot;
    android:gravity=&quot;center&quot;  
    android:layout_marginTop=&quot;80dp&quot;
    /&gt;  
    &amp;lt;TextView    
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Object Sender Activity&quot;
    android:gravity=&quot;center&quot;  
    android:layout_marginTop=&quot;80dp&quot;
    /&gt; 
&amp;lt;Button  
    android:id=&quot;@+id/btnsend&quot;  
    android:layout_width=&quot;fill_parent&quot;  
    android:layout_height=&quot;wrap_content&quot;  
    android:text=&quot;Send Parcelable Object&quot; 
    android:textSize=&quot;25px&quot; 
    android:layout_marginTop=&quot;15dp&quot;
/&gt; 
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5qJs7ecHZkfkZlCd1-NHrA0mgsGqK9wxosTtfPVwXNd-F31Zj0HbgD0mSpPoii6dEOjBOFBs55ZlbJvDzXEpRsfh_p9HoRWqRhuSyj1i9DmZdiU-85dy4NQKRsCVzLpYrtwfodmrWi7I/s1600/Pass_Custom_Object_using_Parcelable_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5qJs7ecHZkfkZlCd1-NHrA0mgsGqK9wxosTtfPVwXNd-F31Zj0HbgD0mSpPoii6dEOjBOFBs55ZlbJvDzXEpRsfh_p9HoRWqRhuSyj1i9DmZdiU-85dy4NQKRsCVzLpYrtwfodmrWi7I/s400/Pass_Custom_Object_using_Parcelable_1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;  src/layout/maintwo.xml:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;
    &amp;lt;TextView    
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Obecjt Reciver Activity&quot;
    android:gravity=&quot;center&quot;  
    android:layout_marginTop=&quot;80dp&quot;
    android:textSize=&quot;25px&quot;
    /&gt; 
    &amp;lt;TextView    
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Data Recived from Sender Activity:-&quot;
    android:layout_marginTop=&quot;80dp&quot;
    android:id=&quot;@+id/txtrev&quot;
    android:textSize=&quot;25px&quot;
    /&gt; 
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;

&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrLLXX0Ycm2D-xtIzDA1QM4nOjonlEB6sEI9gj1nGBEecA1oOBuYv-4w0R0xhneLMGunOY06_AZDJ5zd1QLyyfDf6lnSul360inE3UEot5Axzkjkrz5a4J75H0NCl-3n_0UvDJXtxDVCk/s1600/Pass_Custom_Object_using_Parcelable_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrLLXX0Ycm2D-xtIzDA1QM4nOjonlEB6sEI9gj1nGBEecA1oOBuYv-4w0R0xhneLMGunOY06_AZDJ5zd1QLyyfDf6lnSul360inE3UEot5Axzkjkrz5a4J75H0NCl-3n_0UvDJXtxDVCk/s400/Pass_Custom_Object_using_Parcelable_2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;  AndroidManifest.xml:&lt;/b&gt;&lt;/i&gt; :
&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;com.imrankhanandroid.PassdatausingParcelable&quot;
    android:versionCode=&quot;1&quot;
    android:versionName=&quot;1.0&quot; &gt;
    &amp;lt;uses-sdk android:minSdkVersion=&quot;7&quot; /&gt;
    &amp;lt;application
        android:icon=&quot;@drawable/ic_launcher&quot;
        android:label=&quot;@string/app_name&quot; &gt;
        &amp;lt;activity
            android:label=&quot;@string/app_name&quot;
            android:name=&quot;.ObjectSenderActivity&quot; &gt;
            &amp;lt;intent-filter &gt;
                &amp;lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                &amp;lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &amp;lt;/intent-filter&gt;
        &amp;lt;/activity&gt;
        &amp;lt;activity android:name=&quot;.ObjectReceiverActivity&quot;&gt;&amp;lt;/activity&gt;
    &amp;lt;/application&gt;
&amp;lt;/manifest&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br/&gt;

Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/PassdatausingParcelable.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;PassdatausingParcelable&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/8706799966435613475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-custom-object-using-parcelable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/8706799966435613475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/8706799966435613475'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/pass-custom-object-using-parcelable.html' title='Pass Custom Object Using Parcelable: Android'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5qJs7ecHZkfkZlCd1-NHrA0mgsGqK9wxosTtfPVwXNd-F31Zj0HbgD0mSpPoii6dEOjBOFBs55ZlbJvDzXEpRsfh_p9HoRWqRhuSyj1i9DmZdiU-85dy4NQKRsCVzLpYrtwfodmrWi7I/s72-c/Pass_Custom_Object_using_Parcelable_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-4641286552371187851</id><published>2012-05-25T01:39:00.000-07:00</published><updated>2012-06-03T01:46:56.510-07:00</updated><title type='text'>Pass Custom Object Using Serializable : Android</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div&gt;&lt;br /&gt;
Serialization is a process of reading or writing an object. It is a process of saving an object’s state to a sequence of bytes, as well as a process of rebuilding those bytes back into a live object at some future time. An object is marked serializable by implementing the java.io.Serializable interface, which is only a marker interface -- it simply allows the serialization mechanism to verify that the class can be persisted, typically to a file. &lt;br /&gt;
Transient variables cannot be serialized. The fields marked transient in a serializable object will not be transmitted in the byte stream. An example would be a file handle, a database connection, a system thread etc. Such objects are only meaningful locally. So they should be marked as transient in a serializable class. &lt;br /&gt;
Serialization can adversely affect performance since it: &lt;ul&gt;&lt;li&gt;Depends on reflection.&lt;/li&gt;
&lt;li&gt;Has an incredibly verbose data format.&lt;/li&gt;
&lt;li&gt;Is very easy to send surplus data..&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Example Pass Custom Object by implementing Serializable interface:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;Create  Person.java an Serializable class:&lt;/b&gt;&lt;/i&gt; : &lt;pre class=&quot;brush: java&quot;&gt;package com.imrankhanandroid.Passdserialzedata;

import java.io.Serializable;

//Person Serializable Class
public class Person implements Serializable {
 //serialVersionUID generated by serialver tool.
 private static final long serialVersionUID = 10275439472837494L; 
    private String name;  
    private int age;  
    public String getName() {  
        return name;  
    }  
    public void setName(String name) {  
        this.name = name;  
    }  
    public int getAge() {  
        return age;  
    }  
    public void setAge(int age) {  
        this.age = age;  
    }  
}
&lt;/pre&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;Create  ObejctSenderActivity Activity:&lt;/b&gt;&lt;/i&gt; : &lt;pre class=&quot;brush: java&quot;&gt;package com.imrankhanandroid.Passdserialzedata;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ObejctSenderActivity extends Activity {
 private Button sButton;  
    public  final static String SER_KEY = 
            &quot;com.imrankhanandroid.Passdserialzedata.ser&quot;;  

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sButton = (Button)findViewById(R.id.btnsend); 
        sButton.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    SerializeMethod();
   }
  });
    }
  //Serializeable Passing objects  
    public void SerializeMethod(){ 
     //Create an mPerson Object of Person Class
        Person mPerson = new Person();  
        mPerson.setName(&quot;Imran Khan&quot;);  
        mPerson.setAge(25);  
        //Create an Intent for Passing to startActivity
        Intent mIntent = new Intent(this,ObjectReceiverActivity.class);  
        Bundle mBundle = new Bundle();  
        //put mPerson in bundle using putSerializable
        mBundle.putSerializable(SER_KEY,mPerson);  
        mIntent.putExtras(mBundle);  
          
        startActivity(mIntent);  
    }  
}
&lt;/pre&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;Create  ObjectReceiverActivity Activity:&lt;/b&gt;&lt;/i&gt; : &lt;pre class=&quot;brush: java&quot;&gt;package com.imrankhanandroid.Passdserialzedata;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;


public class ObjectReceiverActivity  extends Activity{
 TextView txtview;
  /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maintwo);
        //Get person object from Intent deliver to ObjectReceiverActivity
        Person mPerson = (Person)getIntent()
        .getSerializableExtra(ObejctSenderActivity.SER_KEY);
        txtview=(TextView)findViewById(R.id.txtrev);
        txtview.append(Html.fromHtml(&quot;
Person Name :&quot;+mPerson.getName()
          +&quot;
Person Age :&quot;+mPerson.getAge()));
    }
}
&lt;/pre&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;res/layout/main.xml:&lt;/b&gt;&lt;/i&gt; : &lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

&amp;lt;TextView    
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Welcome to Imran Khan&#39;s Blog.&quot;
    android:gravity=&quot;center&quot;  
    android:layout_marginTop=&quot;80dp&quot;
    /&gt;  
    &amp;lt;TextView    
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Object Sender Activity&quot;
    android:gravity=&quot;center&quot;  
    android:layout_marginTop=&quot;80dp&quot;
    /&gt; 
&amp;lt;Button  
    android:id=&quot;@+id/btnsend&quot;  
    android:layout_width=&quot;fill_parent&quot;  
    android:layout_height=&quot;wrap_content&quot;  
    android:text=&quot;Send Serializable Object&quot; 
    android:textSize=&quot;25px&quot; 
    android:layout_marginTop=&quot;15dp&quot;
/&gt;  

&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT889HxfugJQ0kMoESSxyyKY5mQtqfIa1KgU1gJ40f2niUdhUKsR60sUG4TUWk26GGgvQrn6YZewRl1qwz_X4mBoOfh93rBJTivrZXDUJwbuSYbDReBklHNisln2btTWZ40aP0qD3Jzek/s1600/Pass_Custom_Object_using_Serializable_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT889HxfugJQ0kMoESSxyyKY5mQtqfIa1KgU1gJ40f2niUdhUKsR60sUG4TUWk26GGgvQrn6YZewRl1qwz_X4mBoOfh93rBJTivrZXDUJwbuSYbDReBklHNisln2btTWZ40aP0qD3Jzek/s400/Pass_Custom_Object_using_Serializable_1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;res/layout/maintwo.xml:&lt;/b&gt;&lt;/i&gt; : &lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;
    &amp;lt;TextView    
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Obecjt Reciver Activity&quot;
    android:gravity=&quot;center&quot;  
    android:layout_marginTop=&quot;80dp&quot;
    android:textSize=&quot;25px&quot;
    /&gt; 
    &amp;lt;TextView    
    android:layout_width=&quot;fill_parent&quot;   
    android:layout_height=&quot;wrap_content&quot;   
    android:text=&quot;Data Recived from Sender Activity:-&quot;
    android:layout_marginTop=&quot;80dp&quot;
    android:id=&quot;@+id/txtrev&quot;
    android:textSize=&quot;25px&quot;
    /&gt; 
&amp;lt;/LinearLayout&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjePbtpTdya3JCcrtoQ5JHawAuGku1CA442WXNlNHlzbto4kiKxf4DPNbL9OIRPWOEugWdVTjxUb9M7lcI7yEeccNuoHWJ8hG6bi4hqDb8b-_smHK2yO048xcyCR62RTa6vTv7ca_E5FCU/s1600/Pass_Custom_Object_using_Serializable_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjePbtpTdya3JCcrtoQ5JHawAuGku1CA442WXNlNHlzbto4kiKxf4DPNbL9OIRPWOEugWdVTjxUb9M7lcI7yEeccNuoHWJ8hG6bi4hqDb8b-_smHK2yO048xcyCR62RTa6vTv7ca_E5FCU/s400/Pass_Custom_Object_using_Serializable_2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;b&gt;res/layout/maintwo.xml:&lt;/b&gt;&lt;/i&gt; : &lt;pre class=&quot;brush: xml&quot;&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&amp;lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;com.imrankhanandroid.Passdserialzedata&quot;
    android:versionCode=&quot;1&quot;
    android:versionName=&quot;1.0&quot; &gt;

    &amp;lt;uses-sdk android:minSdkVersion=&quot;7&quot; /&gt;

    &amp;lt;application
        android:icon=&quot;@drawable/ic_launcher&quot;
        android:label=&quot;@string/app_name&quot; &gt;
        &amp;lt;activity
            android:label=&quot;Welcome to Imran Khan&#39;s Blog.&quot;
            android:name=&quot;.ObejctSenderActivity&quot; &gt;
            &amp;lt;intent-filter &gt;
                &amp;lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                &amp;lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &amp;lt;/intent-filter&gt;
        &amp;lt;/activity&gt;
        &amp;lt;activity android:name=&quot;.ObjectReceiverActivity&quot;&gt;&amp;lt;/activity&gt;
    &amp;lt;/application&gt;

&amp;lt;/manifest&gt;
&lt;/pre&gt;&lt;br /&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/PassdatausingSerializable.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;PassdatausingSerializable&lt;/a&gt; &lt;/div&gt;&lt;br /&gt;
&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/4641286552371187851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/06/pass-custom-object-using-serializable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/4641286552371187851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/4641286552371187851'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/06/pass-custom-object-using-serializable.html' title='Pass Custom Object Using Serializable : Android'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhT889HxfugJQ0kMoESSxyyKY5mQtqfIa1KgU1gJ40f2niUdhUKsR60sUG4TUWk26GGgvQrn6YZewRl1qwz_X4mBoOfh93rBJTivrZXDUJwbuSYbDReBklHNisln2btTWZ40aP0qD3Jzek/s72-c/Pass_Custom_Object_using_Serializable_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-7404399224334430299</id><published>2012-05-24T20:50:00.001-07:00</published><updated>2012-05-24T20:50:24.113-07:00</updated><title type='text'>Android: Handle Screen Orientation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Android:Handle Screen Orientation in Your Application:
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;1.&amp;nbsp;Lock the Orientation in Current Activity&lt;/b&gt;:-
&lt;br/&gt; 
       &amp;nbsp;&amp;nbsp;&amp;nbsp;In the &lt;i&gt;onCreate(Bundle)&lt;/i&gt; method of the current activity use the &lt;i&gt;setRequestedOrientation(int)&lt;/i&gt; method to set the screen orientation. &lt;br/&gt;
The activity will stay in this orientation regardless of if the device is tilted or not.
&lt;br/&gt;
Java code:&lt;br/&gt;&lt;pre class=&quot;brush: java&quot;&gt;
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(
    ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}&lt;/pre&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;2.&amp;nbsp; Detect the Current Screen Orientation:-&lt;/b&gt;&lt;br/&gt;
      &amp;nbsp;&amp;nbsp;&amp;nbsp;Orientation property of the Configuration class returns four possible values corresponding to LANDSCAPE, PORTRAIT, SQUARE and UNDEFINED.
&lt;br/&gt;
Java Code:&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;
switch(this.getResources().getConfiguration().orientation)
{
case Configuration.ORIENTATION_PORTRAIT:
  // Do something here
  break;
case Configuration.ORIENTATION_LANDSCAPE:
  // Do something here
  break;
case Configuration.ORIENTATION_SQUARE:
  // Do something here
  break;
case Configuration.ORIENTATION_UNDEFINED:
  // Do something here
  break;
default:
  throw new Exception(&quot;Unexpected orientation enumeration returned&quot;);
  break;
}
&lt;/pre&gt;
&lt;br/&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTxLu8edSrWVyktmZ_ezwy0yOWbW0xIoHiPSIpkC3_dz7sQ9uLDoFD1kxUrmsR0pByiWUYuJIgDyB9vU9neqw0pYY98ENV-tqNu03wJg9LyhrdzimvfmB4EUrgB-93I1X91Ir8TosWBeQ/s1600/SCREEN_ORIENTATION.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;266&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTxLu8edSrWVyktmZ_ezwy0yOWbW0xIoHiPSIpkC3_dz7sQ9uLDoFD1kxUrmsR0pByiWUYuJIgDyB9vU9neqw0pYY98ENV-tqNu03wJg9LyhrdzimvfmB4EUrgB-93I1X91Ir8TosWBeQ/s400/SCREEN_ORIENTATION.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;br/&gt;
&lt;b&gt;3.&amp;nbsp;Re-enable screen rotation for Appliction:-&lt;/b&gt;&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;To enable the orientation to be automatically changed on device tilt simply pass the setRequestedOrientation(int) method the enumeration  value for an unspecified orientation.&lt;br/&gt;

&lt;pre class=&quot;brush: java&quot;&gt;
// Allow screen rotations again
this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/ScreenorientationApp.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;ScreenorientationApp&lt;/a&gt;
&lt;br /&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/7404399224334430299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-handle-screen-orientation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/7404399224334430299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/7404399224334430299'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-handle-screen-orientation.html' title='Android: Handle Screen Orientation'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTxLu8edSrWVyktmZ_ezwy0yOWbW0xIoHiPSIpkC3_dz7sQ9uLDoFD1kxUrmsR0pByiWUYuJIgDyB9vU9neqw0pYY98ENV-tqNu03wJg9LyhrdzimvfmB4EUrgB-93I1X91Ir8TosWBeQ/s72-c/SCREEN_ORIENTATION.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-4694910483429804155</id><published>2012-05-23T12:02:00.000-07:00</published><updated>2012-05-23T12:02:52.673-07:00</updated><title type='text'>Android : Way of Using setOnClickListener for an View</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I&#39;m going to use most common View Button for Setting onClick event :&lt;br/&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxs9gjRWBhnC8p-FM63NiI9i6ZMazB1zdc5usoc9h8Ybz-Rw9PZfPNKerWIF2ygsBxj02UuhzT-7mmFKJ1wJEI3ynoannS1gepdY_uBr42LiYWbzP4RNkNGn29Rpo3SAH-cjjBHp6Msjg/s1600/View_onclicklistner.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;303&quot; width=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxs9gjRWBhnC8p-FM63NiI9i6ZMazB1zdc5usoc9h8Ybz-Rw9PZfPNKerWIF2ygsBxj02UuhzT-7mmFKJ1wJEI3ynoannS1gepdY_uBr42LiYWbzP4RNkNGn29Rpo3SAH-cjjBHp6Msjg/s400/View_onclicklistner.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;



&lt;b&gt;Method One&lt;/b&gt;:-  One Listener for One button:
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
    Button btn = (Button) findViewById(R.id.myButton); 
    btn. SetOnClickListener (new View.OnClickListener() { 
    Public void onClick(View v) the { 
      // Do Something 
     } 
    }); 
&lt;/pre&gt;	
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Method Two&lt;/b&gt;:-  Share  One Listener with Multiple buttons:
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
  Button btn = (Button)findViewById(R.id.mybutton); 
  Button btn2 = (Button)findViewById(R.id.mybutton2); 
  btn.setOnClickListener(handler); 
  btn2.setOnClickListener(handler); 
  View.OnClickListener handler = View.OnClickListener() { 
  Public void onClick(View v) the { 
  switch(v.getId()) { 
  case R.id.mybutton: 
  // Do Something 
  break; 
  case R.id.mybutton2: 
  // Do Something 
  break; 
    } 
  }
  &lt;/pre&gt;&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;Method Three&lt;/b&gt;:- Clicklistener bundled with an XML the layout of the Views element, Listener methods defined in the program with a View type of parameters as:&lt;br/&gt;

&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
Buttontst.Xml :

&lt;Button android:id=&quot;@+id/mybutton&quot; 
&lt;br&gt;
android:layout_height=&quot;wrap_content&quot;

android:layout_width=&quot;wrap_content&quot; 

android:onClick=&quot;mybuttonlistener&quot;
&lt;/Button&gt;

java code::

  Button btn = (Button) findViewById(R.id.mybutton);
  public void mybuttonlistener(View target){
   //do something
  }

&lt;/pre&gt;
&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/4694910483429804155/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-way-of-using-setonclicklistener.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/4694910483429804155'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/4694910483429804155'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-way-of-using-setonclicklistener.html' title='Android : Way of Using setOnClickListener for an View'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxs9gjRWBhnC8p-FM63NiI9i6ZMazB1zdc5usoc9h8Ybz-Rw9PZfPNKerWIF2ygsBxj02UuhzT-7mmFKJ1wJEI3ynoannS1gepdY_uBr42LiYWbzP4RNkNGn29Rpo3SAH-cjjBHp6Msjg/s72-c/View_onclicklistner.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-5741080208061603084</id><published>2012-05-22T14:10:00.000-07:00</published><updated>2012-05-22T14:10:26.170-07:00</updated><title type='text'>Android open the System Settings interface : Android</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Often need to open the system settings interface:&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;1. Open WirelessSettings:&lt;/b&gt;&lt;br/&gt;
&lt;pre class=&quot;brush:java&quot;&gt;&lt;br /&gt;
Intent intent = new Intent(&quot;/&quot;);
ComponentName cm = new ComponentName(&quot;com.android.settings&quot;,
&quot;com.android.settings.WirelessSettings&quot;);
intent.setComponent(cm);
intent.setAction(&quot;android.intent.action.VIEW&quot;);
Activity.this.startActivityForResult( intent , 0);
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;2. Open GPS Settings:&lt;/b&gt;&lt;br/&gt;
&lt;pre class=&quot;brush:java&quot;&gt;&lt;br /&gt;
Intent intent = new Intent(android.provider.
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
Activity.this.startActivityForResult( intent , 0);
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;3. Open Development Settings:&lt;/b&gt;&lt;br/&gt;
&lt;pre class=&quot;brush:java&quot;&gt;&lt;br /&gt;
Intent intent = new Intent(&quot;/&quot;);
ComponentName cm = new ComponentName(&quot;com.android.settings&quot;,
&quot;com.android.settings.DevelopmentSettings&quot;);
intent.setComponent(cm);
intent.setAction(&quot;android.intent.action.VIEW&quot;);
Activity.this.startActivityForResult( intent , 0);
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;4. Open Activity Picker:&lt;/b&gt;&lt;br/&gt;
&lt;pre class=&quot;brush:java&quot;&gt;&lt;br /&gt;
Intent intent = new Intent(&quot;/&quot;);
ComponentName cm = new ComponentName(&quot;com.android.settings&quot;,
&quot;com.android.settings.ActivityPicker&quot;);
intent.setComponent(cm);
intent.setAction(&quot;android.intent.action.VIEW&quot;);
Activity.this.startActivityForResult( intent , 0);
&lt;/pre&gt;
&lt;br/&gt;
&lt;b&gt;5. Open Language Settings&lt;/b&gt;&lt;br/&gt;
&lt;pre class=&quot;brush:java&quot;&gt;&lt;br /&gt;
Intent intent = new Intent(&quot;/&quot;);
ComponentName cm = new ComponentName(&quot;com.android.settings&quot;,
&quot;com.android.settings.LanguageSettings&quot;);
intent.setComponent(cm);
intent.setAction(&quot;android.intent.action.VIEW&quot;);
Activity.this.startActivityForResult( intent , 0);
&lt;/pre&gt;&lt;br/&gt;
In same way use the following fields directly  to open the corresponding system interface:&lt;br/&gt;
&lt;div style=&quot;font-size:14px;&quot;&gt;
&lt;pre class=&quot;brush:java&quot; style=&quot;font-size:14px;&quot;&gt;&lt;br /&gt;
com.android.settings.AccessibilitySettings //Accessibility settings

com.android.settings.ActivityPicker   //Select activities

com.android.settings.ApnSettings // APN settings

com.android.settings.ApplicationSettings // Application Settings

com.android.settings.BandMode // GSM / UMTS bands

com.android.settings.BatteryInfo  // battery information

com.android.settings.DateTimeSettings  //date and time setting

com.android.settings.DateTimeSettingsSetupWizard //date and time settings Wizard

com.android.settings.DevelopmentSettings  //application settings 

com.android.settings.DeviceAdminSettings //device manager

com.android.settings.DeviceInfoSettings // mobile phones info

com.android.settings.Display - //Set the font size 

com.android.settings.DisplaySettings //display settings

com.android.settings.DockSettings //base settings

com.android.settings.IccLockSettings //SIM card lock settings

com.android.settings.InstalledAppDetails //Installed Application Details

com.android.settings.LanguageSettings //language and keyboard settings

com.android.settings.LocalePicker //select the phone language

com.android.settings.MasterClear //restore factory settings

com.android.settings.MediaFormat //formatting the phone memory

com.android.settings.PhysicalKeyboardSettings //set the keyboard

com.android.settings.PrivacySettings //privacy settings

com.android.settings.ProxySelector //proxy settings

com.android.settings.RadioInfo //phone information

com.android.settings.RunningServices //running programs (services)

com.android.settings.SecuritySettings //location and security settings

com.android.settings.Settings //system settings

com.android.settings.SettingsSafetyLegalActivity //safety information

com.android.settings.SoundSettings //sound settings

com.android.settings.TestingSettings // Displays the phone, battery, usage statistics, Wifi information, service information

com.android.settings.TetherSettings //Tethring Settings

com.android.settings.UsageStats //Usage statistics

com.android.settings.UserDictionarySettings // user dictionary&lt;/pre&gt;&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/5741080208061603084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-open-system-settings-interface.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/5741080208061603084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/5741080208061603084'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-open-system-settings-interface.html' title='Android open the System Settings interface : Android'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-4669253365516648834</id><published>2012-05-20T10:47:00.000-07:00</published><updated>2012-05-22T09:44:13.199-07:00</updated><title type='text'>Android: TimerTask Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br/&gt;&lt;br/&gt;
The TimerTask class represents a task to run at a specified time. The task may be run once or repeatedly.&lt;br/&gt;&lt;br/&gt;
TimerTask Class Methods:&lt;br/&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg23KZB1uSYwie3f-nf5Jc4zxrVuBygFg-KFsooFnhgVdVmCWnicnUSsOtHUw7d7YW1t5B7aC-hkus6SNX4v0ddfbBGcq4bc5__6yehnviV729Nw1sPyiNfnwAddO1_u5-EMmW6I6D9BRc/s1600/TimerTask_Android.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;208&quot; width=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg23KZB1uSYwie3f-nf5Jc4zxrVuBygFg-KFsooFnhgVdVmCWnicnUSsOtHUw7d7YW1t5B7aC-hkus6SNX4v0ddfbBGcq4bc5__6yehnviV729Nw1sPyiNfnwAddO1_u5-EMmW6I6D9BRc/s400/TimerTask_Android.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br/&gt;&lt;br/&gt;

&lt;b&gt;TimerTask  Example:&lt;/b&gt;
&lt;br/&gt;&lt;br/&gt;
TimerTaskExample.java:
&lt;br/&gt;&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
package com.imrankhanandroid.TimerTaskExamp;

import java.util.Timer;
import java.util.TimerTask;
import android.util.Log;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class TimerTaskExample extends Activity {
    /** Called when the activity is first created. */
    private static String  TAG = &quot;TimerTaskExample&quot;; 
 
    private TextView mTextView = null;  
    private Button mButton_start = null;  
    private Button mButton_pause = null;  
  
    private Timer mTimer = null;  
    private TimerTask mTimerTask = null;  
  
    private Handler mHandler = null;  
      
    private static int count = 0;  
    private boolean isPause = false;  
    private boolean isStop = true;  
  
    private static int delay = 1000;  //1s  
    private static int period = 1000;  //1s  
  
    private static final int UPDATE_TEXTVIEW = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mTextView = (TextView)findViewById(R.id.mytextview);   
        mButton_start = (Button)findViewById(R.id.mybutton_start);  
        mButton_pause = (Button)findViewById(R.id.mybutton_pause);
        mButton_start.setOnClickListener(new 
        Button.OnClickListener() {  
            public void onClick(View v) {  
                if (isStop) {  
                    Log.i(TAG, &quot;Start&quot;);  
                } else {  
                    Log.i(TAG, &quot;Stop&quot;);  
                }  
                isStop = !isStop;  
                if (!isStop) {  
                    startTimer();  
                }else {  
                    stopTimer();  
                }  
                if (isStop) {  
                    mButton_start.setText(R.string.start);  
                } else {  
                    mButton_start.setText(R.string.stop);  
                }  
            }  
        }); 
        mButton_pause.setOnClickListener(new 
        Button.OnClickListener() {  
            public void onClick(View v) {  
                if (isPause) {  
                    Log.i(TAG, &quot;Resume&quot;);  
                } else {  
                    Log.i(TAG, &quot;Pause&quot;);  
                }  
                isPause = !isPause;  
                if (isPause) {  
                    mButton_pause.setText(R.string.resume);  
                } else {  
                    mButton_pause.setText(R.string.pause);  
                }  
            }  
        });  
          
        mHandler = new Handler(){  
            @Override  
            public void handleMessage(Message msg) {  
                switch (msg.what) {  
                case UPDATE_TEXTVIEW:  
                    updateTextView();  
                    break;  
                default:  
                    break;  
                }  
            }  
        };  
    }  
  
    private void updateTextView(){  
        mTextView.setText(String.valueOf(count));  
    }  
  
    private void startTimer(){  
        if (mTimer == null) {  
            mTimer = new Timer();  
        }  
        if (mTimerTask == null) {  
            mTimerTask = new TimerTask() {  
                @Override  
                public void run() {  
                    Log.i(TAG, &quot;count: &quot;+String.valueOf(count));  
                    sendMessage(UPDATE_TEXTVIEW);  
                      
                    do {  
                        try {  
                            Log.i(TAG, &quot;sleep(1000)...&quot;);  
                            Thread.sleep(1000);  
                        } catch (InterruptedException e) {  
                        }     
                    } while (isPause);   
                    count ++;    
                }  
            };  
        }  
        if(mTimer != null &amp;&amp; mTimerTask != null )  
            mTimer.schedule(mTimerTask, delay, period);  
    }  
  
    private void stopTimer(){  
          
        if (mTimer != null) {  
            mTimer.cancel();  
            mTimer = null;  
        }  
        if (mTimerTask != null) {  
            mTimerTask.cancel();  
            mTimerTask = null;  
        }     
        count = 0;  
    }  
      
    public void sendMessage(int id){  
        if (mHandler != null) {  
            Message message = Message.obtain(mHandler, id);     
            mHandler.sendMessage(message);   
        }  
    }  
 
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl3xhTnB_ox1VHOIher8yDa7J6Iqlsw_f3F2QrmhKhoGqavhcEe_eoTxcxODYzG7jeSoOmaP96M9rbW4ypBoHUzGT2aJXIkjw-SLgsVTV3nkQIcwraBk1ivvYqKg4Gr9TWPAbfL280NCg/s1600/TimerTask_Android_Example.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;266&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl3xhTnB_ox1VHOIher8yDa7J6Iqlsw_f3F2QrmhKhoGqavhcEe_eoTxcxODYzG7jeSoOmaP96M9rbW4ypBoHUzGT2aJXIkjw-SLgsVTV3nkQIcwraBk1ivvYqKg4Gr9TWPAbfL280NCg/s400/TimerTask_Android_Example.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;




&lt;br /&gt;&lt;br /&gt;

main.xml:
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&lt;br /&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

    &lt;TextView  
        android:id=&quot;@+id/mytextview&quot;  
        android:layout_width=&quot;fill_parent&quot;  
        android:layout_height=&quot;wrap_content&quot;  
        android:gravity=&quot;center&quot; 
        android:textSize=&quot;60dp&quot;
        android:layout_marginTop=&quot;40dp&quot;
        android:text=&quot;@string/number&quot; /&gt;  
  
    &lt;LinearLayout  
        android:layout_width=&quot;fill_parent&quot;  
        android:layout_height=&quot;wrap_content&quot;  
        android:gravity=&quot;center&quot;  
        android:layout_marginTop=&quot;30dp&quot;
        android:orientation=&quot;horizontal&quot; &gt;  
  
        &lt;Button  
            android:id=&quot;@+id/mybutton_start&quot;  
            android:layout_width=&quot;wrap_content&quot;  
            android:layout_height=&quot;wrap_content&quot;  
            android:textSize=&quot;30dp&quot; 
            android:text=&quot;@string/start&quot; /&gt;  
  
        &lt;Button  
            android:id=&quot;@+id/mybutton_pause&quot;  
            android:layout_width=&quot;wrap_content&quot;  
            android:layout_height=&quot;wrap_content&quot;  
            android:textSize=&quot;30dp&quot; 
            android:text=&quot;@string/pause&quot; /&gt;  
    &lt;/LinearLayout&gt;  
&lt;/LinearLayout&gt;
&lt;/pre&gt;
&lt;br /&gt;

strings.xml.xml:
&lt;br /&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&lt;br /&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;
    &lt;string name=&quot;app_name&quot;&gt;TimerTaskExample&lt;/string&gt; 
    &lt;string name=&quot;number&quot;&gt;0&lt;/string&gt;  
    &lt;string name=&quot;start&quot;&gt;start&lt;/string&gt;  
    &lt;string name=&quot;stop&quot;&gt;stop&lt;/string&gt;  
    &lt;string name=&quot;pause&quot;&gt;pause&lt;/string&gt;  
    &lt;string name=&quot;resume&quot;&gt;resume&lt;/string&gt;  
&lt;/resources&gt;
&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/TimerTaskExample.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;TimerTaskExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/4669253365516648834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-timertask-example.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/4669253365516648834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/4669253365516648834'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-timertask-example.html' title='Android: TimerTask Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg23KZB1uSYwie3f-nf5Jc4zxrVuBygFg-KFsooFnhgVdVmCWnicnUSsOtHUw7d7YW1t5B7aC-hkus6SNX4v0ddfbBGcq4bc5__6yehnviV729Nw1sPyiNfnwAddO1_u5-EMmW6I6D9BRc/s72-c/TimerTask_Android.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4613043958095018301.post-856590265834719400</id><published>2012-05-20T08:03:00.000-07:00</published><updated>2012-05-22T09:46:41.602-07:00</updated><title type='text'>Android : CountDownTimer</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;&lt;br /&gt;
CountDownTimer is used for Schedule a countdown until a time in the future, with regular notifications on intervals along the way.
&lt;br /&gt;&lt;br /&gt;
CountDownTimer methods:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO-fiBE94mo4t5h_tL1MFOyzOH2D7TOnV-kw8_lsKScGOh0ZsO4TQmtnhYbtzDyS3jye3p80ya1OJYQc2jgVg0451h2v_ecQRTlt0nWII4DuSeTT3qTSh-AKy7MYhl633TZYooaxNsvkQ/s1600/Counterdowntimer_Android.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;251&quot; width=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO-fiBE94mo4t5h_tL1MFOyzOH2D7TOnV-kw8_lsKScGOh0ZsO4TQmtnhYbtzDyS3jye3p80ya1OJYQc2jgVg0451h2v_ecQRTlt0nWII4DuSeTT3qTSh-AKy7MYhl633TZYooaxNsvkQ/s400/Counterdowntimer_Android.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;CountDownTimer Example&lt;/b&gt;:&lt;br/&gt;&lt;br/&gt;
RunOnUiThreadExample.java:&lt;br/&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&lt;br /&gt;&lt;br /&gt;
package com.imrankhanandroid.CountDownTimer;

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;
import android.widget.Toast;

public class CountDownTimerExample extends Activity {
    /** Called when the activity is first created. */
 private MyCount mc;  
    private TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView)findViewById(R.id.show);  
        mc = new MyCount(30000, 1000);  
        mc.start();
    }
    /* Define a countdown internal class */
    class MyCount extends CountDownTimer {     
            public MyCount(long millisInFuture, 
              long countDownInterval) {     
                super(millisInFuture, countDownInterval);     
            }     
            @Override     
            public void onFinish() {     
                tv.setText(&quot;finish!!!&quot;);        
            }     
            @Override     
            public void onTick(long millisUntilFinished) {     
                tv.setText(&quot;Please wait for 30 seconds.&quot; +
                &quot;(&quot; + millisUntilFinished / 1000 + &quot;)...&quot;);     
       //Toast show the time delay  
                Toast.makeText(CountDownTimerExample.this,
                millisUntilFinished / 1000 + &quot;&quot;, 
                Toast.LENGTH_LONG).show();      
            }    
        } 
}
&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioJFj1ajauvs0ZxpVfQ3pohusi5alyybusNzl3dz2PzvsuFoFH5sajOmvvsyet7RVWbvxcISJgiJZ81IT8c8Yr0urtC_F3M78hsTmdfFjYMaXT_JG1FXnSNzaqa-cJiT4vW-nDGUHkuRU/s1600/CountDownTimer_Android.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; width=&quot;267&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioJFj1ajauvs0ZxpVfQ3pohusi5alyybusNzl3dz2PzvsuFoFH5sajOmvvsyet7RVWbvxcISJgiJZ81IT8c8Yr0urtC_F3M78hsTmdfFjYMaXT_JG1FXnSNzaqa-cJiT4vW-nDGUHkuRU/s400/CountDownTimer_Android.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;br/&gt;&lt;br/&gt;
main.xml:&lt;br/&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;br /&gt;&lt;br /&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:orientation=&quot;vertical&quot; &gt;

    &lt;TextView
        android:id=&quot;@+id/show&quot;
        android:layout_width=&quot;fill_parent&quot;
        android:textSize=&quot;30dp&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:text=&quot;@string/hello&quot; /&gt;

&lt;/LinearLayout&gt;
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;
Download Source Code: &lt;a href=&quot;https://sites.google.com/site/imrankhanandroid/CountDownTimerExample.rar?attredirects=0&amp;d=1&quot; target=&quot;_blank&quot;&gt;CountDownTimerExample&lt;/a&gt;

&lt;div style=&#39;width:0%;&#39;&gt;&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shCore.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;link href=&#39;http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css&#39; rel=&#39;stylesheet&#39; type=&#39;text/css&#39;/&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script src=&#39;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js&#39; type=&#39;text/javascript&#39;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script language=&#39;javascript&#39;&gt;
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
&lt;/script&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://androidimran.blogspot.com/feeds/856590265834719400/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-countdowntimer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/856590265834719400'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4613043958095018301/posts/default/856590265834719400'/><link rel='alternate' type='text/html' href='http://androidimran.blogspot.com/2012/05/android-countdowntimer.html' title='Android : CountDownTimer'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13512928438375644582</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO-fiBE94mo4t5h_tL1MFOyzOH2D7TOnV-kw8_lsKScGOh0ZsO4TQmtnhYbtzDyS3jye3p80ya1OJYQc2jgVg0451h2v_ecQRTlt0nWII4DuSeTT3qTSh-AKy7MYhl633TZYooaxNsvkQ/s72-c/Counterdowntimer_Android.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>