<?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-4980586312959306498</id><updated>2026-09-30T15:54:41.344+05:30</updated><category term="Android"/><category term="ArrayAdapter"/><category term="Xml"/><category term="Example"/><category term="ListView"/><category term="Galary"/><category term="GridView"/><category term="Menu"/><category term="SubMenu"/><category term="TabHost"/><category term="TabWidget"/><title type='text'>LEARN ANDROID</title><subtitle type='html'>Android All Example for learning different things.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-5407299524496144426</id><published>2012-09-10T11:03:00.003+05:30</published><updated>2012-09-10T11:03:25.044+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="ArrayAdapter"/><category scheme="http://www.blogger.com/atom/ns#" term="Example"/><category scheme="http://www.blogger.com/atom/ns#" term="ListView"/><category scheme="http://www.blogger.com/atom/ns#" term="Xml"/><title type='text'>Multiple Views in Sinlge List with ListView and Other Control - Hotel Menu Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In this Code We will use multiple Views in a single list as well as put a Button below the list which use to show how many items will be selected in another new Activities.&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/AVvXsEjo5lOAkfQoySqd3L6V6zwVri5pnwjqsk7OpMVnUng4h5wFQrhYHYxOhD6r538s2xVQUTeBLFZHAJjzSYIRkaVRcHC-LkYQFMjmiXTseM-30f816XcWoFNo_MIVoYb2vnvSFI4Y9MulfVPl/s1600/hotelmenu2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&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/AVvXsEjGec6z0EAG1BhGPqEDPhTt7z4hVuNnhvwfT3b44KxOVsvMkaJtjjKZn253liVEpAVqqhXrKpHZFAihsi2QVQqs0VuIbBZceRcj7r0W3vIqIRaxXEm9lnJI0VmKRWfgRCmZ5Y1zhUzdOpp8/s1600/hotelmenu3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&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/AVvXsEjo5lOAkfQoySqd3L6V6zwVri5pnwjqsk7OpMVnUng4h5wFQrhYHYxOhD6r538s2xVQUTeBLFZHAJjzSYIRkaVRcHC-LkYQFMjmiXTseM-30f816XcWoFNo_MIVoYb2vnvSFI4Y9MulfVPl/s1600/hotelmenu2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo5lOAkfQoySqd3L6V6zwVri5pnwjqsk7OpMVnUng4h5wFQrhYHYxOhD6r538s2xVQUTeBLFZHAJjzSYIRkaVRcHC-LkYQFMjmiXTseM-30f816XcWoFNo_MIVoYb2vnvSFI4Y9MulfVPl/s320/hotelmenu2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9; color: #444444; font-family: Arial,Tahoma,Helvetica,FreeSans,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0OElCSWJMNVNOSW8&quot; style=&quot;color: #3778cd; font-size: x-large; font-weight: bold; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Download Android Multiple Views in Single List Demo Example Code&lt;/a&gt; &lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;First We will create the layout of each row as follows layout/rowlayout.xml. &lt;br /&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;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
	android:orientation=&quot;horizontal&quot; android:layout_width=&quot;fill_parent&quot;
	android:layout_height=&quot;fill_parent&quot;&amp;gt;
	
	&amp;lt;ImageView android:layout_height=&quot;60px&quot; 
		android:id=&quot;@+id/imageView1&quot;
		android:layout_width=&quot;60px&quot; 
		android:src=&quot;@drawable/icon&quot; 
		android:maxWidth=&quot;5px&quot;
		android:minWidth=&quot;5px&quot;
		/&amp;gt;
	&amp;lt;TextView android:text=&quot;TextView&quot; 
		android:layout_width=&quot;200dp&quot;
		android:layout_height=&quot;wrap_content&quot; 
		android:id=&quot;@+id/textView1&quot;
		android:lines=&quot;2&quot;
		android:layout_marginLeft=&quot;10px&quot;
		android:layout_marginTop=&quot;10px&quot; 
		android:textSize=&quot;15px&quot;
		&amp;gt;&amp;lt;/TextView&amp;gt;
	&amp;lt;CheckBox android:text=&quot;&quot; 
	android:id=&quot;@+id/checkBox1&quot; 
	android:layout_width=&quot;wrap_content&quot; 
	android:layout_height=&quot;wrap_content&quot; /&amp;gt;
	
&amp;lt;/LinearLayout&amp;gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Than we create our main layout as follows layout/main.xml &lt;br /&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;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    &amp;gt;
&amp;lt;ListView 
    android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:id=&quot;@android:id/list&quot;
    /&amp;gt;
  &amp;lt;Button android:layout_width=&quot;wrap_content&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:id=&quot;@+id/btnOrder&quot; 
    android:text=&quot;Order&quot; 
    android:layout_gravity=&quot;center&quot;/&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/pre&gt;
Here the name of the listView must be as aboves : &quot;@android:id/list&quot; where android list will be automatically placed when we add the adapter in our activity class. &lt;/li&gt;
&lt;li&gt;Then we create a class which extend the ArrayAdapter&amp;nbsp; class as follows. &lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt; 
package com.container;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.container.R;

public class HotelMenuAdapter extends ArrayAdapter&amp;lt;String&amp;gt; {
	Context context;
	String[] values;
	int position;
	boolean itemSelected[] = { false, false, false, false, false, false };

	public HotelMenuAdapter(Context context, String[] values) {
		super(context, R.layout.rowlayout, values);
		this.context = context;
		this.values = values;
	}

	public View getView(final int positon, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.rowlayout, parent, false);

		TextView textView = (TextView) rowView.findViewById(R.id.textView1);
		ImageView image = (ImageView) rowView.findViewById(R.id.imageView1);
		final CheckBox checkBox = (CheckBox) rowView
				.findViewById(R.id.checkBox1);

		image.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Toast.makeText(context, ((TextView)v).getText().toString(),
				// 5).show();
				if (checkBox.isChecked()) {
					checkBox.setChecked(false);
					itemSelected[positon] = false;
				} else {
					checkBox.setChecked(true);
					itemSelected[positon] = true;
				}
			}
		});

		textView.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Toast.makeText(context, ((TextView)v).getText().toString(),
				// 5).show();
				if (checkBox.isChecked()) {
					checkBox.setChecked(false);
					itemSelected[positon] = false;
				} else {
					checkBox.setChecked(true);
					itemSelected[positon] = true;
				}
			}
		});

		checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				// TODO Auto-generated method stub
				// Toast.makeText(context, String.valueOf(positon), 5).show();
				if (isChecked) {
					itemSelected[positon] = true;
					// Toast.makeText(context, &quot;Checked&quot;, 5).show();
				} else {

					itemSelected[positon] = false;
					// Toast.makeText(context, &quot;Not Checked&quot;, 5).show();
				}

			}
		});

		textView.setText(values[positon]);
		switch (positon) {
		case 0:
			image.setImageResource(R.drawable.a);
			break;
		case 1:
			image.setImageResource(R.drawable.b);
			break;
		case 2:
			image.setImageResource(R.drawable.c);
			break;
		case 3:
			image.setImageResource(R.drawable.d);
			break;
		case 4:
			image.setImageResource(R.drawable.e);
			break;
		case 5:
			image.setImageResource(R.drawable.f);
			break;
		case 6:
			image.setImageResource(R.drawable.g);
			break;

		}

		checkBox.setChecked(false);
		return rowView;
	}

	public boolean[] getItemSelected() {
		return itemSelected;
	}

	public void setItemSelected(boolean[] itemSelected) {
		this.itemSelected = itemSelected;
	}

}
&lt;/pre&gt;
In this class we also add the listeners for the ImageView, TextView as well as CheckBoxes.&lt;br /&gt;&lt;br /&gt; 
&lt;/li&gt;
&lt;li&gt;Then in our main Activity class we will extends the ListActivity class as follows.  &lt;br /&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.container;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

public class HotelMenuDemoActivity extends ListActivity {
	/** Called when the activity is first created. */
	String[] values = { &quot;McVeggie~Rs.40-50&quot;, &quot;McAloo Tikki~Rs 20–50&quot;,
			&quot;Paneer Salsa~Rs 20–50&quot;, &quot;Crispy Chinese~Rs 20–50&quot;,
			&quot;McCurry Pan~Rs 20–50&quot;, &quot;Chicken Maharaja Mac&quot;, };
	Button btnOrder;
	CheckBox chBox;
	HotelMenuAdapter menuAdapter;

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		menuAdapter = new HotelMenuAdapter(getApplicationContext(), values);
		setListAdapter(menuAdapter);

		btnOrder = (Button) findViewById(R.id.btnOrder);
		btnOrder.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				boolean [] selectedItem=menuAdapter.getItemSelected();
				int count=0;
				Intent intent=new Intent(getApplicationContext(),ShowOrderActivity.class);
				for(int i=0;i&amp;lt;selectedItem.length;i++){
					if(selectedItem[i]==true){
						count++;
						intent.putExtra(&quot;items&quot;,values);
						intent.putExtra(&quot;selected&quot;,selectedItem);
				//	Toast.makeText(getApplicationContext(), menuAdapter.getItem(i),5).show();
					}
				}
				startActivity(intent);
			}
		});

	}
}&lt;/pre&gt;
&lt;/li&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;li&gt;Finally We will create the another activity which just show the items witch is selected. as follows.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.container;

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

public class ShowOrderActivity extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		TextView tv = new TextView(this);
		tv.setMaxLines(10);
		Bundle b = getIntent().getExtras();
		String order = &quot;Your Order is : \n&quot;;
		String[] values = (String[]) b.getSerializable(&quot;items&quot;);
		boolean[] items = (boolean[]) b.getSerializable(&quot;selected&quot;);
		if (items != null &amp;amp;&amp;amp; values != null) {
			for (int i = 0; i &amp;lt; values.length; i++) {
				if (items[i] == true)
					order += values[i] + &quot;,\n&quot;;
			}
		}
		tv.setText(order);
		setContentView(tv);
		// TODO Auto-generated method stub
	}

}
&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
That&#39;s the code:&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;When you click on the ImageView,TextView or Checkbox&amp;nbsp; corresponding Checkbox will be checked or unchecked in reverse state.&amp;nbsp; as follows &lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRLhY0sFnHRkLlQaREhMDkHRAubZXu6yWKWEZn5BnImVD-mASXNuZ-vV60bNxmhX5KORUC-PjhMyElgu-2hQxUlg1Te_D33Zdxj2zsLGKW5oAnyv8Tu_LcMpaKz1T5MWqMY-CX_dvqkW8h/s1600/hotelmenu1.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRLhY0sFnHRkLlQaREhMDkHRAubZXu6yWKWEZn5BnImVD-mASXNuZ-vV60bNxmhX5KORUC-PjhMyElgu-2hQxUlg1Te_D33Zdxj2zsLGKW5oAnyv8Tu_LcMpaKz1T5MWqMY-CX_dvqkW8h/s320/hotelmenu1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;After selecting which ever items you want click on &quot;Order&quot; Button than following&amp;nbsp; output will be displayed.&amp;nbsp;&lt;/li&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGec6z0EAG1BhGPqEDPhTt7z4hVuNnhvwfT3b44KxOVsvMkaJtjjKZn253liVEpAVqqhXrKpHZFAihsi2QVQqs0VuIbBZceRcj7r0W3vIqIRaxXEm9lnJI0VmKRWfgRCmZ5Y1zhUzdOpp8/s1600/hotelmenu3.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGec6z0EAG1BhGPqEDPhTt7z4hVuNnhvwfT3b44KxOVsvMkaJtjjKZn253liVEpAVqqhXrKpHZFAihsi2QVQqs0VuIbBZceRcj7r0W3vIqIRaxXEm9lnJI0VmKRWfgRCmZ5Y1zhUzdOpp8/s320/hotelmenu3.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/5407299524496144426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/09/multiple-views-in-sinlge-list-with.html#comment-form' title='23 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/5407299524496144426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/5407299524496144426'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/09/multiple-views-in-sinlge-list-with.html' title='Multiple Views in Sinlge List with ListView and Other Control - Hotel Menu Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEjo5lOAkfQoySqd3L6V6zwVri5pnwjqsk7OpMVnUng4h5wFQrhYHYxOhD6r538s2xVQUTeBLFZHAJjzSYIRkaVRcHC-LkYQFMjmiXTseM-30f816XcWoFNo_MIVoYb2vnvSFI4Y9MulfVPl/s72-c/hotelmenu2.png" height="72" width="72"/><thr:total>23</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-8187320989784830308</id><published>2012-09-03T15:50:00.000+05:30</published><updated>2012-09-03T15:50:37.058+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="Example"/><category scheme="http://www.blogger.com/atom/ns#" term="TabHost"/><category scheme="http://www.blogger.com/atom/ns#" term="TabWidget"/><category scheme="http://www.blogger.com/atom/ns#" term="Xml"/><title type='text'>Android TabLayout example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&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/AVvXsEheprbpHHUq_NpLNDUooUEaeKIM9U0vVEZSJIHe7Ih8fwJ5E0L9Rihmn-QdU-h1ql9TJxp8Tm2c03lkXviZlmBWC7Pp09d8wXknGZrBl8nkh7v5Muc1sIhOhJPZwym1LjMR5kFXmGZLxQQ8/s1600/multipleView2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;
In this example we have three tab as follows. you can move in the any tab at by clicking on the Tab. as follows &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&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/AVvXsEjSV5AmjEIAnubg-v-TxPj9DYJRQfQFxG6TH2orEnUxA6AdhmfohPB0LEQC-DFxCZ_jkuZSLlQWMWu-S8UaVmKhgL8WbMyJE0HzfIfA8uKRJ0OGfdL7emQr1WijbO0n399Pc2ReHPj6OZcC/s1600/TAB1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSV5AmjEIAnubg-v-TxPj9DYJRQfQFxG6TH2orEnUxA6AdhmfohPB0LEQC-DFxCZ_jkuZSLlQWMWu-S8UaVmKhgL8WbMyJE0HzfIfA8uKRJ0OGfdL7emQr1WijbO0n399Pc2ReHPj6OZcC/s320/TAB1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0M2FtSmt0SXY5M2c&quot; style=&quot;color: #3778cd; font-size: x-large; font-weight: bold; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Download Android Tab Layout :Example Code&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;First we design the XML layout as follows &lt;br /&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;?&amp;gt;
&amp;lt;TabHost xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
 android:id=&quot;@android:id/tabhost&quot; android:layout_width=&quot;match_parent&quot;
 android:layout_height=&quot;match_parent&quot;&amp;gt;
 &amp;lt;LinearLayout android:id=&quot;@+id/linearLayout1&quot;
  android:layout_width=&quot;match_parent&quot; android:layout_height=&quot;match_parent&quot;
  android:orientation=&quot;vertical&quot;&amp;gt;
  &amp;lt;TabWidget android:layout_width=&quot;match_parent&quot;
   android:layout_height=&quot;wrap_content&quot; 
   android:id=&quot;@android:id/tabs&quot;&amp;gt;&amp;lt;/TabWidget&amp;gt;
  &amp;lt;FrameLayout android:layout_width=&quot;match_parent&quot;
   android:layout_height=&quot;match_parent&quot; android:id=&quot;@android:id/tabcontent&quot;&amp;gt;
   
  &amp;lt;/FrameLayout&amp;gt;
 &amp;lt;/LinearLayout&amp;gt;
&amp;lt;/TabHost&amp;gt;

&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Create the Activtity file for diffrent Tab Activities we have create three diffrent Activity : ActivityA, ActivityB, ActivityC as follows &lt;/li&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.container;

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

public class ActivityA extends Activity {

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     TextView tv=new TextView(this);
     tv.setText(&quot;I am in Tab A..&quot;);
     setContentView(tv);
     // TODO Auto-generated method stub
 }

}
&lt;/pre&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.container;

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

public class ActivityB extends Activity {

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     TextView tv=new TextView(this);
     tv.setText(&quot;I am in Tab B..&quot;);
     setContentView(tv);
     // TODO Auto-generated method stub
 }

}
&lt;/pre&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.container;

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

public class ActivityC extends Activity {

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     TextView tv=new TextView(this);
     tv.setText(&quot;I am in Tab C..&quot;);
     setContentView(tv);
     // TODO Auto-generated method stub
 }

}
&lt;/pre&gt;
&lt;li&gt;Than we Create Our main Activity as follows code..&lt;/li&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.container;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class TabViewDemoActivity extends TabActivity {
    /** Called when the activity is first created. */
 Resources res;
 TabHost tabHost;
 TabHost.TabSpec spec;
 Intent intent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        res=getResources();
        tabHost=getTabHost();
        
        /**Create Tab A**/
        intent=new Intent().setClass(this,ActivityA.class);
        spec=tabHost.newTabSpec(&quot;A&quot;)
          .setIndicator(&quot;A&quot;,res.getDrawable(R.drawable.ic_btn_speak_now))
          .setContent(intent);
        tabHost.addTab(spec);
        
        /**Create Tab B**/
        intent=new Intent().setClass(this,ActivityB.class);
        spec=tabHost.newTabSpec(&quot;B&quot;)
          .setIndicator(&quot;B&quot;,res.getDrawable(R.drawable.ic_btn_speak_now))
          .setContent(intent);
        tabHost.addTab(spec);
        
        /**Create Tab C**/
        intent=new Intent().setClass(this,ActivityC.class);
        spec=tabHost.newTabSpec(&quot;C&quot;)
          .setIndicator(&quot;C&quot;,res.getDrawable(R.drawable.ic_btn_speak_now))
          .setContent(intent);
        tabHost.addTab(spec);
    }
}&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;/ol&gt;
that it, Run your app you can move on any Tab By clicking on that as follows
&lt;br /&gt;
&lt;pre&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/AVvXsEjr8zAN2AvbYEphbLdzm4AJVG5HVMFStwjWlBy94BTXm2v_Bhg3vTHavV4siHO6riFGqGEFEyE4_dd_sZdwehbWLtDVaqm9FNS5rLPZRg4lRP_Dw3rQhn-5S9mZ1mSXm6z2Olvs7idHujed/s1600/TAB2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr8zAN2AvbYEphbLdzm4AJVG5HVMFStwjWlBy94BTXm2v_Bhg3vTHavV4siHO6riFGqGEFEyE4_dd_sZdwehbWLtDVaqm9FNS5rLPZRg4lRP_Dw3rQhn-5S9mZ1mSXm6z2Olvs7idHujed/s320/TAB2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/8187320989784830308/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-tablayout-example.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/8187320989784830308'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/8187320989784830308'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-tablayout-example.html' title='Android TabLayout example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEjSV5AmjEIAnubg-v-TxPj9DYJRQfQFxG6TH2orEnUxA6AdhmfohPB0LEQC-DFxCZ_jkuZSLlQWMWu-S8UaVmKhgL8WbMyJE0HzfIfA8uKRJ0OGfdL7emQr1WijbO0n399Pc2ReHPj6OZcC/s72-c/TAB1.png" height="72" width="72"/><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-1916942117115276411</id><published>2012-08-30T21:17:00.002+05:30</published><updated>2012-09-03T16:03:31.110+05:30</updated><title type='text'>Android Custom ArrayAdapte-ListView - Example Code</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In this Example we show how to Add Multiple View in the Single Row of the ListView Control. We take two Controls ImageView and TextView as Shown follows.&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/AVvXsEgblqTpRZwvmKmPLsyZHvVR2EDhlk5WY_H0Sx8378NbBkvXYe0NR3LHm2XjmhOf0bGMNx0PA5xI69EA9xFdZvcYlVADpsWye03Rhgm_T_-B3KxMRBO8pcg_R6CZRkqhnUlBoNfMakosfega/s1600/multipleView1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgblqTpRZwvmKmPLsyZHvVR2EDhlk5WY_H0Sx8378NbBkvXYe0NR3LHm2XjmhOf0bGMNx0PA5xI69EA9xFdZvcYlVADpsWye03Rhgm_T_-B3KxMRBO8pcg_R6CZRkqhnUlBoNfMakosfega/s320/multipleView1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt; &lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0cUV3VDhBS1NGVm8&quot; style=&quot;font-size: x-large; font-weight: bold;&quot; target=&quot;_blank&quot;&gt;Download Custom ArrayAdapte-ListView - Code Example&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;First We Create the layout file for the following that is as fllows : res/layout/rawlayout.xml&lt;br /&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;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
 android:orientation=&quot;horizontal&quot; android:layout_width=&quot;match_parent&quot;
 android:layout_height=&quot;match_parent&quot;&amp;gt;
 
 &amp;lt;ImageView android:layout_height=&quot;wrap_content&quot; 
  android:id=&quot;@+id/imageView1&quot;
  android:layout_width=&quot;wrap_content&quot; 
  android:src=&quot;@drawable/icon&quot; /&amp;gt;

 &amp;lt;TextView android:text=&quot;TextView&quot; 
  android:layout_width=&quot;wrap_content&quot;
  android:layout_height=&quot;wrap_content&quot; 
  android:id=&quot;@+id/textView1&quot; 
  android:layout_marginLeft=&quot;10px&quot;
  android:layout_marginTop=&quot;10px&quot; 
  android:textSize=&quot;20px&quot;
  &amp;gt;&amp;lt;/TextView&amp;gt;

&amp;lt;/LinearLayout&amp;gt;

&lt;/pre&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Then We Create The Custom ArrayAdapter Class Which will create by extending ArrayAdapter Class that has a &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;i&gt;getView()&lt;/i&gt;&lt;/span&gt; method that use to set how we want customize our row layout of&amp;nbsp; for each raw of ListView
&lt;br /&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.container;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyArrayAdapter extends ArrayAdapter&amp;lt;String&amp;gt; {
 Context context;
 String[] values;

 public MyArrayAdapter(Context context, String[] values) {
  super(context, R.layout.rowlayout, values);
  this.context = context;
  this.values = values;
 }

 public View getView(int positon, View convertView, ViewGroup parent) {
  LayoutInflater inflater = (LayoutInflater) context
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View rowView = inflater.inflate(R.layout.rowlayout, parent, false);

  TextView textView = (TextView) rowView.findViewById(R.id.textView1);
  ImageView image = (ImageView) rowView.findViewById(R.id.imageView1);

  textView.setText(values[positon]);
  if (positon % 2 == 0) {
   image.setImageResource(R.drawable.yes);
  } else {
   image.setImageResource(R.drawable.no);
  }
  return rowView;
 }
}
&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Then We create the Our Activity Class which extends the ListActivity class in which we have set the Adapter of using the method&amp;nbsp; &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;i&gt;setListAdapter()&lt;/i&gt;&lt;/span&gt; which has an argument of our own MyArrayAdapter class instance. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.container;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;


public class MultipleViewListActivity extends ListActivity{
    
 String [] values= {&quot;Android&quot;, &quot;iPhone&quot;, &quot;WindowsMobile&quot;,
             &quot;Blackberry&quot;, &quot;WebOS&quot;, &quot;Ubuntu&quot;, &quot;Windows7&quot;, &quot;Max OS X&quot;,
             &quot;Linux&quot;, &quot;OS/2&quot;};;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setListAdapter(new MyArrayAdapter(getApplicationContext(), values));
    }

 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
  // TODO Auto-generated method stub
  Toast.makeText(getApplicationContext(), values[position], 5).show();
  //super.onListItemClick(l, v, position, id);
 }
}&lt;/pre&gt;
&lt;/li&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;/ol&gt;
When you click on any of the ListItem than The Toast is appear with the Name in that TextView.&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/AVvXsEheprbpHHUq_NpLNDUooUEaeKIM9U0vVEZSJIHe7Ih8fwJ5E0L9Rihmn-QdU-h1ql9TJxp8Tm2c03lkXviZlmBWC7Pp09d8wXknGZrBl8nkh7v5Muc1sIhOhJPZwym1LjMR5kFXmGZLxQQ8/s1600/multipleView2.png&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheprbpHHUq_NpLNDUooUEaeKIM9U0vVEZSJIHe7Ih8fwJ5E0L9Rihmn-QdU-h1ql9TJxp8Tm2c03lkXviZlmBWC7Pp09d8wXknGZrBl8nkh7v5Muc1sIhOhJPZwym1LjMR5kFXmGZLxQQ8/s320/multipleView2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ4XwGoAqZt8o4Vxsz838EkhReEX-GggXp2wJdmju2BILAyCW7eHMHIUi7Xfrx13lcIDCYZNu5dpPZogNPJYW8hylEVS0tVniMNAQ568ClWwOawl9DKoaSBM70hxnPg89uK-rvzUScXA8B/s1600/multipleView2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/1916942117115276411/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-custom-arrayadapte-listview.html#comment-form' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/1916942117115276411'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/1916942117115276411'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-custom-arrayadapte-listview.html' title='Android Custom ArrayAdapte-ListView - Example Code'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEgblqTpRZwvmKmPLsyZHvVR2EDhlk5WY_H0Sx8378NbBkvXYe0NR3LHm2XjmhOf0bGMNx0PA5xI69EA9xFdZvcYlVADpsWye03Rhgm_T_-B3KxMRBO8pcg_R6CZRkqhnUlBoNfMakosfega/s72-c/multipleView1.png" height="72" width="72"/><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-6995964055065513592</id><published>2012-08-29T17:56:00.000+05:30</published><updated>2012-08-29T17:56:28.044+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="ArrayAdapter"/><category scheme="http://www.blogger.com/atom/ns#" term="GridView"/><category scheme="http://www.blogger.com/atom/ns#" term="Xml"/><title type='text'>Android GridView tutorial and Example Code</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;h2&gt;
GridView:&lt;/h2&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Contains a horizontally scrolling list of View objects, also often used&amp;nbsp;with image icons; the user can select an item to perform some action upon.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0YTNWTGxFOEIwQWs&quot; style=&quot;color: #3778cd; font-size: x-large; font-weight: bold; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Download Android GridView Container :Example Code&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Let&#39;s take Simple Example which shows the Grid of &amp;nbsp;TextView that will be display as grid on Screen and you can select on of them.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The Layout of this app is as follows : main.xml&amp;nbsp;&lt;/div&gt;
&lt;div&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;?&amp;gt;
&amp;lt;GridView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:id=&quot;@+id/gridView01&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    android:columnWidth=&quot;90dp&quot;
    android:numColumns=&quot;2&quot;
    android:verticalSpacing=&quot;10dp&quot;
    android:horizontalSpacing=&quot;10dp&quot;
    android:stretchMode=&quot;columnWidth&quot;
    android:gravity=&quot;center&quot;
    /&amp;gt;
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
The Java file can be as follows.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt; 
package com.container;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class GridViewContainerActivity extends Activity {
    /** Called when the activity is first created. */
    GridView gv;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        String [] colors= {&quot;Red&quot;,&quot;Green&quot;,&quot;Blue&quot;,&quot;Pink&quot;,&quot;Gray&quot;};
        gv=(GridView)findViewById(R.id.gridView01);
        
        ArrayAdapter&amp;lt;String&amp;gt; adapter=new ArrayAdapter&amp;lt;String&amp;gt;(getApplicationContext(), android.R.layout.simple_gallery_item, colors);
        gv.setAdapter(adapter);
        gv.setNumColumns(3);
        gv.setBackgroundColor(Color.CYAN);
        gv.setGravity(Gravity.CENTER);
        gv.setOnItemClickListener(new OnItemClickListener() {

   public void onItemClick(AdapterView&amp;lt;?&amp;gt; myAdapter, View view, int myItemId,
     long myLang) {
    // TODO Auto-generated method stub
    
    String selectedItem=gv.getItemAtPosition(myItemId).toString();
  
    Toast.makeText(getApplicationContext(), selectedItem, 2).show();
   }
  });
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
When you first run your app that will shown as follows.&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/AVvXsEhbpruEuazF5qF8WTQ48yh1kesrYSatVB8CxYslyN3wJZ6Gv0NGb78t02ouAGLNvkQN45cAmNbWpyoW6dJmzLB8HRFh1IQW4faCn8az_em9KzIQSxG-ey4I24lItprlNcAAd_qjXFfay4de/s1600/gridview1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbpruEuazF5qF8WTQ48yh1kesrYSatVB8CxYslyN3wJZ6Gv0NGb78t02ouAGLNvkQN45cAmNbWpyoW6dJmzLB8HRFh1IQW4faCn8az_em9KzIQSxG-ey4I24lItprlNcAAd_qjXFfay4de/s320/gridview1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&amp;nbsp;For example you select &quot;Green&quot; than following output will be displayed.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4GIgB-wL-29kXZcHXLEPs56GZunxS6JfQAmBk8epFVKXkkq5UyPnbGoTv1_8hx0a4v0s8DgYzuzoAR9zwqWLA1TZGPimnbWJ5ZNjT_HE2Ogxn5oOckB-CyUI-qU8nu9dwtGT8UMC06qnT/s1600/gridview2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4GIgB-wL-29kXZcHXLEPs56GZunxS6JfQAmBk8epFVKXkkq5UyPnbGoTv1_8hx0a4v0s8DgYzuzoAR9zwqWLA1TZGPimnbWJ5ZNjT_HE2Ogxn5oOckB-CyUI-qU8nu9dwtGT8UMC06qnT/s320/gridview2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/6995964055065513592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-gridview-tutorial-and-example.html#comment-form' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/6995964055065513592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/6995964055065513592'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-gridview-tutorial-and-example.html' title='Android GridView tutorial and Example Code'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEhbpruEuazF5qF8WTQ48yh1kesrYSatVB8CxYslyN3wJZ6Gv0NGb78t02ouAGLNvkQN45cAmNbWpyoW6dJmzLB8HRFh1IQW4faCn8az_em9KzIQSxG-ey4I24lItprlNcAAd_qjXFfay4de/s72-c/gridview1.png" height="72" width="72"/><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-8227177566495111478</id><published>2012-08-29T17:30:00.003+05:30</published><updated>2012-08-29T17:45:27.719+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="ArrayAdapter"/><category scheme="http://www.blogger.com/atom/ns#" term="Galary"/><category scheme="http://www.blogger.com/atom/ns#" term="Xml"/><title type='text'>Android Galary Container : Code Example </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2&gt;
Galary:&lt;/h2&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Contains a horizontally scrolling list of View objects, also often used&amp;nbsp;with image icons; the user can select an item to perform some action upon.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0WkRZaDVuUnMycTQ&quot; style=&quot;color: #3778cd; font-size: x-large; font-weight: bold; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Download Android Galary Container :Example Code&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Let&#39;s take Simple Example which shows the Galary of &amp;nbsp;TextView that will be scrolled horizontally and you can select on of them.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The Layout of this app is as follows : main.xml&amp;nbsp;&lt;/div&gt;
&lt;div&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;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    &amp;gt;
 &amp;lt;TextView android:text=&quot;Select Color&quot;
  android:id=&quot;@+id/textView1&quot;
  android:textAppearance=&quot;?android:attr/textAppearanceLarge&quot;
  android:layout_width=&quot;wrap_content&quot; 
  android:layout_height=&quot;wrap_content&quot;
  /&amp;gt;
  
 &amp;lt;Gallery android:layout_width=&quot;fill_parent&quot;
  android:layout_height=&quot;wrap_content&quot;
   android:id=&quot;@+id/gallary01&quot; 
   android:spacing=&quot;100px&quot; 
  android:layout_gravity=&quot;center&quot;/&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;
The Java file can be as follows.
&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt; 
package com.container;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Gallery;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class GalaryContainerDemoActivity extends Activity {
    /** Called when the activity is first created. */
 Gallery g;
 TextView tv;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        String [] colors= {&quot;Red&quot;,&quot;Green&quot;,&quot;Blue&quot;,&quot;Pink&quot;,&quot;Gray&quot;};
        g=(Gallery)findViewById(R.id.gallary01);
        tv=(TextView)findViewById(R.id.textView1);
        ArrayAdapter&amp;lt;String&amp;gt; adapter=new ArrayAdapter&amp;lt;String&amp;gt;(getApplicationContext(), android.R.layout.simple_gallery_item, colors);
        g.setAdapter(adapter);
        
        g.setOnItemClickListener(new OnItemClickListener() {

   public void onItemClick(AdapterView&amp;lt;?&amp;gt; myAdapter, View view, int myItemId,
     long myLang) {
    // TODO Auto-generated method stub
    
    String selectedItem=g.getItemAtPosition(myItemId).toString();
    tv.setText(&quot;You Selected: &quot;+ selectedItem);
    Toast.makeText(getApplicationContext(), selectedItem, 2).show();
   }
  });
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
When you first run your app that will shown as follows.&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/AVvXsEgVNrUXCAr65k4LS2CdwKJdlW8_rxH3qOtHbX6UI_mfQgVG8K9Wo12Pp7qxg_IMvG3dJFWZlhjtcXEOuOGfB8F_H1ix_h0NfLN8P3-pv-ms_0V_1DyncpGuvixtFEB0155_kQ611qsm6Izc/s1600/galary1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVNrUXCAr65k4LS2CdwKJdlW8_rxH3qOtHbX6UI_mfQgVG8K9Wo12Pp7qxg_IMvG3dJFWZlhjtcXEOuOGfB8F_H1ix_h0NfLN8P3-pv-ms_0V_1DyncpGuvixtFEB0155_kQ611qsm6Izc/s320/galary1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;You can scroll horizontally using touch.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcC67VPo4NHCFaxTIt5E4c6wlFskN83hEq105_fXi2hBrjhyphenhyphenTy5TD4ebTkpsg-XraITOXmd-f4fKNaDhdjVNjp_OFsmfU-9LpUcAAty2-5_8jPgz8STiOzOpIy7IV6xm01RosXpzqdqbDa/s1600/galary2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcC67VPo4NHCFaxTIt5E4c6wlFskN83hEq105_fXi2hBrjhyphenhyphenTy5TD4ebTkpsg-XraITOXmd-f4fKNaDhdjVNjp_OFsmfU-9LpUcAAty2-5_8jPgz8STiOzOpIy7IV6xm01RosXpzqdqbDa/s320/galary2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;For example you select &quot;Green&quot; than following output will be displayed.

&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIEen7Kw2ucZHEmr51FqUZawfnFpg4azlX8Bqr8wRdXhKEFWBY3UG70QBklFmVga8RLRhyphenhyphenw0muUmSg1Pdq2_Ji7HC4cpPdNhuvvs_Yi958hvq7wAUu0Pro-v4trVeC3tGal1zSQ883z16Y/s1600/galary3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIEen7Kw2ucZHEmr51FqUZawfnFpg4azlX8Bqr8wRdXhKEFWBY3UG70QBklFmVga8RLRhyphenhyphenw0muUmSg1Pdq2_Ji7HC4cpPdNhuvvs_Yi958hvq7wAUu0Pro-v4trVeC3tGal1zSQ883z16Y/s320/galary3.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/8227177566495111478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-galary-container-code-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/8227177566495111478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/8227177566495111478'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-galary-container-code-example.html' title='Android Galary Container : Code Example '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEgVNrUXCAr65k4LS2CdwKJdlW8_rxH3qOtHbX6UI_mfQgVG8K9Wo12Pp7qxg_IMvG3dJFWZlhjtcXEOuOGfB8F_H1ix_h0NfLN8P3-pv-ms_0V_1DyncpGuvixtFEB0155_kQ611qsm6Izc/s72-c/galary1.png" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>State Highway 25, Sadar, Rajkot, Gujarat, India</georss:featurename><georss:point>22.3038945 70.8021599</georss:point><georss:box>22.245124999999998 70.723195900000007 22.362664 70.8811239</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-6273205927118824495</id><published>2012-08-29T16:58:00.000+05:30</published><updated>2012-08-29T17:04:56.303+05:30</updated><title type='text'>Android Content Menu using XML file and  Event Handling- Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2&gt;
Context Menu :&lt;/h2&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;The ContextMenu is a subtype of Menu that you can configure to 
display when a long press is performed on a View. As the name implies, 
the ContextMenu provides for contextual menus to display to the user for
 performing additional actions on selected items.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;You need to implement the onCreateContextMenu() method of your 
Activity for one to display. However, before that is called, you must 
call the registerForContextMenu() method and pass in the View for which 
you want to have a context menu. This means each View on your screen can
 have a different context menu, which is appropriate as the menus are 
designed to be highly contextual.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Here we have an example of a Chronometer timer, which responds to a long click with&lt;br /&gt;a context menu:&lt;/li&gt;
&lt;li&gt;We will override onContextItemSelected() to Listen the Item Event Selected &lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0N0xCN0NGSDZzWnM&quot; style=&quot;font-size: x-large; font-weight: bold;&quot; target=&quot;_blank&quot;&gt;Download Android Context Menu :Example Code&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
Context Menu with ItemListener :&lt;/h2&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;We have put two Control &quot;TextView&quot; and &quot;Chronometer&quot; in following main.xml file&lt;/li&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    &amp;gt;
&amp;lt;TextView  
    android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;@string/hello&quot;
    android:id=&quot;@+id/TV01&quot;
    /&amp;gt;
&amp;lt;Chronometer android:text=&quot;Chronometer&quot; 
 android:id=&quot;@+id/chronometer1&quot; 
 android:layout_width=&quot;wrap_content&quot; 
 android:layout_height=&quot;wrap_content&quot; /&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/pre&gt;
&lt;li&gt;We Create Menu using XML file res/menus/menutxt.xml for TextView as follows..&amp;nbsp;&lt;/li&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;menu
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&amp;gt;
    &amp;lt;item android:id=&quot;@+id/M1&quot;
     android:title=&quot;Menu 1&quot; /&amp;gt;
    &amp;lt;item android:id=&quot;@+id/M2&quot;
     android:title=&quot;Menu 2&quot; /&amp;gt;
    &amp;lt;item android:id=&quot;@+id/M3&quot;
     android:title=&quot;Menu 3&quot; /&amp;gt;
&amp;lt;/menu&amp;gt;&lt;/pre&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;/pre&gt;
&lt;li&gt;We Create Menu using XML file res/menus/menucm.xml for TextView as follows.. &lt;/li&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;menu
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&amp;gt;
    &amp;lt;item android:id=&quot;@+id/menuStart&quot;
     android:title=&quot;Start&quot; /&amp;gt;
    &amp;lt;item android:id=&quot;@+id/menuStop&quot;
     android:title=&quot;Stop&quot; /&amp;gt;
    &amp;lt;item android:id=&quot;@+id/menuRestart&quot;
     android:title=&quot;Restart&quot; /&amp;gt;
&amp;lt;/menu&amp;gt;
&lt;/pre&gt;
&lt;li&gt;Then in the following Activity file in the method 
onCreateContextMenu() we have created Menu for TextView &amp;amp; 
Chronometer and Register for each Contrrol and using onContextItemSelected() we will listen the events of Chronometer ..&lt;/li&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.widget;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.Chronometer;
import android.widget.TextView;

public class ContextMenuXmlActivity extends Activity {
    /** Called when the activity is first created. */
 TextView tv;
    Chronometer cm;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        cm=(Chronometer)findViewById(R.id.chronometer1);
        tv=(TextView)findViewById(R.id.TV01);
        registerForContextMenu(cm);
        registerForContextMenu(tv);
    }

 @Override
 public boolean onContextItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
  switch(item.getItemId())
  {
   case R.id.menuStart:
    cm.start();
    break;
   case R.id.menuStop:
    cm.stop();
    break;
   case R.id.menuRestart:
    cm.setBase(android.os.SystemClock.elapsedRealtime());
    break;
  }
  return super.onContextItemSelected(item);
 }

 @Override
 public void onCreateContextMenu(ContextMenu menu, View v,
   ContextMenuInfo menuInfo) {
  // TODO Auto-generated method stub
  if(v.getId()==R.id.TV01)
  {
   getMenuInflater().inflate(R.menu.menutxt, menu);
  }
  if(v.getId()==R.id.chronometer1)
  {
   getMenuInflater().inflate(R.menu.menucm, menu);
   menu.setHeaderIcon(android.R.drawable.ic_media_play);
   menu.setHeaderTitle(&quot;Timer.....&quot;);
  }
  super.onCreateContextMenu(menu, v, menuInfo);
 }
    
}&lt;/pre&gt;
&lt;li&gt;When you long click on Chronometer the following ContextMenu will be displays.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;And you can perform &quot;Start&quot;, &quot;Stop&quot; and &quot;Restart&quot;&amp;nbsp; the Chronometer. &lt;/li&gt;
&lt;li&gt;&amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT49nMwQ1Ks4ipSTfar11ajkmMFPPNO-tkyifmMcDIQL8RgAp714B5P59uYpvUxc2zJtYmhRFZmm822xX2GC-RBoHGJqUZpesuF_zlapn_EYEIT2wBVLaz5wlWcJ0UMmYZJDm7FgZL4vvi/s1600/contextmenu21.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT49nMwQ1Ks4ipSTfar11ajkmMFPPNO-tkyifmMcDIQL8RgAp714B5P59uYpvUxc2zJtYmhRFZmm822xX2GC-RBoHGJqUZpesuF_zlapn_EYEIT2wBVLaz5wlWcJ0UMmYZJDm7FgZL4vvi/s320/contextmenu21.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikH7_zQYvsHbwc6yDcpn92zB9Xws4Sh71AVikYdE4-Es8sqRmqM7bae_qmqeiaSVqdhcEYNkCQAYu2iexv7-QMDyBduEriyIL3Kt46WU4NNsesM0WGsKU2UmFCdcKaTnBMH6NxBxvTJ_RW/s1600/contextmenu22.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikH7_zQYvsHbwc6yDcpn92zB9Xws4Sh71AVikYdE4-Es8sqRmqM7bae_qmqeiaSVqdhcEYNkCQAYu2iexv7-QMDyBduEriyIL3Kt46WU4NNsesM0WGsKU2UmFCdcKaTnBMH6NxBxvTJ_RW/s320/contextmenu22.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/6273205927118824495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-content-menu-using-xml-file-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/6273205927118824495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/6273205927118824495'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-content-menu-using-xml-file-and.html' title='Android Content Menu using XML file and  Event Handling- Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEiT49nMwQ1Ks4ipSTfar11ajkmMFPPNO-tkyifmMcDIQL8RgAp714B5P59uYpvUxc2zJtYmhRFZmm822xX2GC-RBoHGJqUZpesuF_zlapn_EYEIT2wBVLaz5wlWcJ0UMmYZJDm7FgZL4vvi/s72-c/contextmenu21.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-1371444887031262981</id><published>2012-08-29T16:55:00.000+05:30</published><updated>2012-08-29T16:55:20.961+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="Menu"/><category scheme="http://www.blogger.com/atom/ns#" term="SubMenu"/><title type='text'>Android SubMenu with Example </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2&gt;
Submenu&lt;/h2&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Submenus are displayed as regular Menu Items that, when selected, reveal more items.&lt;/li&gt;
&lt;li&gt;Traditionally,submenus are displayed in a hierarchical tree layout. Android uses a different approach to simplify menu navigation for small-screen devices. Rather than a tree structure, selecting a submenu presents a single floating window that displays all of its Menu Items.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;You can add submenus using the &lt;i&gt;addSubMenu()&lt;/i&gt; method. It supports the same parameters as the add method used to add normal Menu Items, enabling you to specify a group, unique identifier, and text string for each submenu. You can also use the &lt;i&gt;setHeaderIcon&lt;/i&gt; and &lt;i&gt;setIcon&lt;/i&gt; methods to specify an iconto display in the submenu’s header bar or icon menu, respectively.&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9;&quot;&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0d3R3MTBxUjgzUVk&quot; style=&quot;font-size: x-large; font-weight: bold;&quot; target=&quot;_blank&quot;&gt;Download Android SubMenu :Example Code&lt;/a&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
We will see an Exaple that will Display SubMenu for Background &amp;amp; TextColor of the Text View Whatever color you will select that will be set as Backfround and Text color respectively &lt;/h4&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt; We will create menu &quot;Text Color&quot; and &quot;Text Color&quot; and add the Sub Menu to these menus.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Using menu/menus.xml file as follows.&lt;/li&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;menu
  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&amp;gt;
    &amp;lt;item android:id=&quot;@+id/TextColor&quot; 
     android:title=&quot;Text Color&quot;&amp;gt;
     &amp;lt;menu &amp;gt;
       &amp;lt;item android:id=&quot;@+id/TextRed&quot; 
        android:title=&quot;Red&quot; /&amp;gt;
       &amp;lt;item android:id=&quot;@+id/TextGreen&quot; 
        android:title=&quot;Green&quot; /&amp;gt;
       &amp;lt;item android:id=&quot;@+id/TextBlue&quot; 
        android:title=&quot;Blue&quot; /&amp;gt;
     &amp;lt;/menu&amp;gt; 
    &amp;lt;/item&amp;gt;
    
    &amp;lt;item android:id=&quot;@+id/BackColor&quot; 
     android:title=&quot;Back Color&quot;&amp;gt;
     &amp;lt;menu &amp;gt;
       &amp;lt;item android:id=&quot;@+id/BackRed&quot; 
        android:title=&quot;Red&quot; /&amp;gt;
       &amp;lt;item android:id=&quot;@+id/BackGreen&quot; 
        android:title=&quot;Green&quot; /&amp;gt;
       &amp;lt;item android:id=&quot;@+id/BackBlue&quot; 
        android:title=&quot;Blue&quot; /&amp;gt;
     &amp;lt;/menu&amp;gt; 
    &amp;lt;/item&amp;gt;
    
&amp;lt;/menu&amp;gt;

&lt;/pre&gt;
&lt;li&gt;We will write the Java code as follows.&lt;/li&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;package com.widget;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class SubMenuXmlActivity extends Activity {
    /** Called when the activity is first created. */
    TextView tv;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.Tv01);
    }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // TODO Auto-generated method stub
  getMenuInflater().inflate(R.menu.menus, menu);
  
  return super.onCreateOptionsMenu(menu);
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
  switch(item.getItemId())
  {
  case R.id.TextRed:
   tv.setTextColor(Color.RED);
   break;
  case R.id.TextGreen:
   tv.setTextColor(Color.GREEN);
   break;
  case R.id.TextBlue:
   tv.setTextColor(Color.BLUE);
   break;
  case R.id.BackRed:
   tv.setBackgroundColor(Color.RED);
   break;
  case R.id.BackGreen:
   tv.setBackgroundColor(Color.GREEN);
   break;
  case R.id.BackBlue:
   tv.setBackgroundColor(Color.BLUE);
   break; 
  }
  return super.onOptionsItemSelected(item);
 }
 
 
}
&lt;/pre&gt;
&lt;li&gt;The OutPut will be as follows First click on Menu Button. That will display two menu as follows&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIC_lRC4SBltfDsOeVn1sf9QU5dXTvL8O0DG2eTh12PlZkEedoMO0tADCwlsWuvRQpUAQCo4M_LskK4NKLjkCCkEuLuCg-6VhbivupSD79i4QfFWeXyc01gp0DaSO0d8Rk-xnocPbKXNC3/s1600/submenu1.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIC_lRC4SBltfDsOeVn1sf9QU5dXTvL8O0DG2eTh12PlZkEedoMO0tADCwlsWuvRQpUAQCo4M_LskK4NKLjkCCkEuLuCg-6VhbivupSD79i4QfFWeXyc01gp0DaSO0d8Rk-xnocPbKXNC3/s320/submenu1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Than suppose we select &quot;Text Color&quot; that show following Submenu for Text Color. &lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuSnpp7S-_54colxqx5QrO9s-thmLVrKP4BSFtSkEykajwQ2j09aULawWrNAOOraiSe5UokMzApfmRg2QZalAf6a7nysU4NTmrURnpVISMthg0_uLLx-RWtzOdWVF5rWUb38km9-TBT6Se/s1600/submenu2.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuSnpp7S-_54colxqx5QrO9s-thmLVrKP4BSFtSkEykajwQ2j09aULawWrNAOOraiSe5UokMzApfmRg2QZalAf6a7nysU4NTmrURnpVISMthg0_uLLx-RWtzOdWVF5rWUb38km9-TBT6Se/s320/submenu2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Suppose if we select &quot;Red&quot; than the Text Color of TextView Will become Red.&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuS6Ze3WZGTAou7FeVogne5GZ46lrWPAJYOVq3Y_eldn5c-uW5g5FbZjQi8LdfqEpAkFPjCroGrkviaGS_pyiTX2XLFOXe2_6pVLGaMT-r8pc8rl6zhfYl-Ujd1cdezsEbQTpBVwWAz-kS/s1600/submenu3.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuS6Ze3WZGTAou7FeVogne5GZ46lrWPAJYOVq3Y_eldn5c-uW5g5FbZjQi8LdfqEpAkFPjCroGrkviaGS_pyiTX2XLFOXe2_6pVLGaMT-r8pc8rl6zhfYl-Ujd1cdezsEbQTpBVwWAz-kS/s320/submenu3.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Than suppose we select &quot;Back Color&quot; that show following Submenu for Back Color. &lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr_I7UKqucZAageN24wuYgLsaXfXMwHb1dJJSI4kr3Fr33VHx_o-z-goQj3JsP2buaYYcFVK1uMzIetE7tr1x6g8NeRqH82mdgHhlFMSCeazp3a6nwJtxrqoa_ZAaOt70MF-TdzAwhT6bn/s1600/submenu4.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr_I7UKqucZAageN24wuYgLsaXfXMwHb1dJJSI4kr3Fr33VHx_o-z-goQj3JsP2buaYYcFVK1uMzIetE7tr1x6g8NeRqH82mdgHhlFMSCeazp3a6nwJtxrqoa_ZAaOt70MF-TdzAwhT6bn/s320/submenu4.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Suppose if we select &quot;Green&quot; than the Background Color of TextView Will become Green.&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&amp;nbsp;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieY8ghy8BsV2nRAXq83vULR3tIvjfV-M6xUS9-ebSNVSvOjAN2ZUwh_057Df3MF5e3KgtYwTJzhRsub8_UXAFKDEi2Ay7vhyphenhyphenoJirM2gbrz0_VorBcNOGZJWUbrX1vKtZS8n51vv46hQc4w/s1600/submenu5.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieY8ghy8BsV2nRAXq83vULR3tIvjfV-M6xUS9-ebSNVSvOjAN2ZUwh_057Df3MF5e3KgtYwTJzhRsub8_UXAFKDEi2Ay7vhyphenhyphenoJirM2gbrz0_VorBcNOGZJWUbrX1vKtZS8n51vv46hQc4w/s320/submenu5.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/1371444887031262981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-submenu-with-example.html#comment-form' title='287 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/1371444887031262981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/1371444887031262981'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-submenu-with-example.html' title='Android SubMenu with Example '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEhIC_lRC4SBltfDsOeVn1sf9QU5dXTvL8O0DG2eTh12PlZkEedoMO0tADCwlsWuvRQpUAQCo4M_LskK4NKLjkCCkEuLuCg-6VhbivupSD79i4QfFWeXyc01gp0DaSO0d8Rk-xnocPbKXNC3/s72-c/submenu1.png" height="72" width="72"/><thr:total>287</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-2684473266368783381</id><published>2012-08-29T16:42:00.003+05:30</published><updated>2012-08-29T17:56:47.503+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="ArrayAdapter"/><category scheme="http://www.blogger.com/atom/ns#" term="ListView"/><title type='text'>Android ListView Tutorial with Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2&gt;
ListView :&lt;/h2&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9; color: #222222; font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px;&quot;&gt;A view that shows items in a vertically scrolling list. The items come from the &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9; color: #222222; font-size: 14px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;courier new&#39;, courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 21px;&quot;&gt;&lt;i&gt;ListAdapter&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Roboto, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 19px;&quot;&gt;&amp;nbsp;associated with this view.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #222222; font-family: Roboto, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 14px; line-height: 19px;&quot;&gt;Contains a vertically scrolling,&amp;nbsp;horizontally&amp;nbsp;filled list of View objects, each of which typically contains a row of data; the user can choose an item to&amp;nbsp;perform&amp;nbsp;some action upon.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #222222;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 14px; line-height: 19px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Roboto, sans-serif;&quot;&gt;In ListView we have set adapter of &lt;/span&gt;&lt;i style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ArrayAdapter &lt;/i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;which gathers data from an Array is generally used when there is only a single column data or when the data comes from a resource array&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Roboto, sans-serif; font-style: italic;&quot;&gt;.&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;; font-size: small; font-style: normal; line-height: normal;&quot;&gt;&lt;h2 align=&quot;center&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0N0xCN0NGSDZzWnM&quot; target=&quot;_blank&quot;&gt;Download Android ListView :Example Code&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9; color: #222222;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Roboto, sans-serif; font-size: 14px; line-height: 19px;&quot;&gt;Let&#39;s see an Example of List View Simply have only one item in each line.as follows. &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9;&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFJU-_8O9-l02OAv1IOSvQ_m0cBzKxOmchOwYo3cxbZ_gHJLohKGSiiBm9uLGglZvHzrKdTWRDGeSCQQmn0r1LE7mHO-oc5h2XiB4aH4pjNbKTSQ1fOa08LVF8wCQyEBhtAbpKPK1YWQj2/s1600/listview1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFJU-_8O9-l02OAv1IOSvQ_m0cBzKxOmchOwYo3cxbZ_gHJLohKGSiiBm9uLGglZvHzrKdTWRDGeSCQQmn0r1LE7mHO-oc5h2XiB4aH4pjNbKTSQ1fOa08LVF8wCQyEBhtAbpKPK1YWQj2/s320/listview1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
First We will create a layout file main.xml as follows:&lt;br /&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;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
 android:orientation=&quot;vertical&quot; android:layout_width=&quot;fill_parent&quot;
 android:layout_height=&quot;fill_parent&quot;&amp;gt;
 &amp;lt;TextView android:text=&quot;Select Color&quot;
  android:id=&quot;@+id/textView1&quot;
  android:textAppearance=&quot;?android:attr/textAppearanceLarge&quot;
  android:layout_width=&quot;wrap_content&quot; 
  android:layout_height=&quot;wrap_content&quot; /&amp;gt;
 &amp;lt;ListView android:layout_width=&quot;fill_parent&quot;
  android:layout_height=&quot;wrap_content&quot;
   android:id=&quot;@+id/listView01&quot; /&amp;gt;

&amp;lt;/LinearLayout&amp;gt;
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Than we will Create a java File as follows :&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.contnr;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListViewContainerActivity extends Activity {
    /** Called when the activity is first created. */
    ListView lv;
    TextView tv;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        String [] colors= {&quot;Red&quot;,&quot;Green&quot;,&quot;Blue&quot;,&quot;Pink&quot;,&quot;Gray&quot;};
        lv=(ListView)findViewById(R.id.listView01);
        tv=(TextView)findViewById(R.id.textView1);
        ArrayAdapter&amp;lt;String&amp;gt; adapter=new ArrayAdapter&amp;lt;String&amp;gt;(getApplicationContext(), android.R.layout.simple_list_item_1, colors);
        lv.setAdapter(adapter);
        
        lv.setOnItemClickListener(new OnItemClickListener() {

   public void onItemClick(AdapterView&amp;lt;?&amp;gt; myAdapter, View view, int myItemId,
     long myLang) {
    // TODO Auto-generated method stub
    
    String selectedItem=lv.getItemAtPosition(myItemId).toString();
    tv.setText(&quot;You Selected: &quot;+ selectedItem);
    Toast.makeText(getApplicationContext(), selectedItem, 2).show();
   }
  });
    }
}&lt;/pre&gt;
When you click on any of the List Item that displayed in Toast and in TextView also as follows....
&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/AVvXsEhCXRLLYIB6_f_ZXbsvWlU3sJ02geY09JGQe3lBSaYZxTFHZtVvNebKmCcskDX7Ek0rpMrg6wpPOBYSR7X5gF8AcLRySSagVLOBYFvxRFGP46EOfFjyX9lL6-DWvWLnu5mMmvAr30HaUyR4/s1600/listview2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCXRLLYIB6_f_ZXbsvWlU3sJ02geY09JGQe3lBSaYZxTFHZtVvNebKmCcskDX7Ek0rpMrg6wpPOBYSR7X5gF8AcLRySSagVLOBYFvxRFGP46EOfFjyX9lL6-DWvWLnu5mMmvAr30HaUyR4/s320/listview2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/2684473266368783381/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-listview-tutorial-with-example.html#comment-form' title='20 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/2684473266368783381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/2684473266368783381'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-listview-tutorial-with-example.html' title='Android ListView Tutorial with Example'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEgFJU-_8O9-l02OAv1IOSvQ_m0cBzKxOmchOwYo3cxbZ_gHJLohKGSiiBm9uLGglZvHzrKdTWRDGeSCQQmn0r1LE7mHO-oc5h2XiB4aH4pjNbKTSQ1fOa08LVF8wCQyEBhtAbpKPK1YWQj2/s72-c/listview1.png" height="72" width="72"/><thr:total>20</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-2931326078019010729</id><published>2012-08-28T21:20:00.001+05:30</published><updated>2012-08-29T17:05:56.696+05:30</updated><title type='text'>Android Context Menu - Example </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2&gt;
Context Menu :&lt;/h2&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;The ContextMenu is a subtype of Menu that you can configure to display when a long press is performed on a View. As the name implies, the ContextMenu provides for contextual menus to display to the user for performing additional actions on selected items.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;You need to implement the onCreateContextMenu() method of your Activity for one to display. However, before that is called, you must call the registerForContextMenu() method and pass in the View for which you want to have a context menu. This means each View on your screen can have a different context menu, which is appropriate as the menus are designed to be highly contextual.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Here we have an example of a Chronometer timer, which responds to a long click with&lt;br /&gt;a context menu:&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #f9f9f9;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0X3NtODNnVkdyNTQ&quot; style=&quot;font-size: x-large; font-weight: bold;&quot; target=&quot;_blank&quot;&gt;Download Android Context Menu :Example Code&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;We have put two Control &quot;TextView&quot; and &quot;Chronometer&quot; in following main.xml file&lt;/li&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    &amp;gt;
&amp;lt;TextView  
    android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;@string/hello&quot;
    android:id=&quot;@+id/TV01&quot;
    /&amp;gt;
&amp;lt;Chronometer android:text=&quot;Chronometer&quot; 
 android:id=&quot;@+id/chronometer1&quot; 
 android:layout_width=&quot;wrap_content&quot; 
 android:layout_height=&quot;wrap_content&quot; /&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/pre&gt;
&lt;li&gt;Then in the following Activity file in the method onCreateContextMenu() we have created Menu for TextView &amp;amp; Chronometer and Register for each Contrrol..&lt;/li&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.widget;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.Chronometer;
import android.widget.TextView;

public class ContextMenuActivity extends Activity {
    /** Called when the activity is first created. */
    TextView tv;
    Chronometer cm;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        cm=(Chronometer)findViewById(R.id.chronometer1);
        tv=(TextView)findViewById(R.id.TV01);
        registerForContextMenu(cm);
        registerForContextMenu(tv);
        
    }

 @Override
 public boolean onContextItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
  // Not any Task that will do with XML
  return super.onContextItemSelected(item);
 }

 @Override
 public void onCreateContextMenu(ContextMenu menu, View v,
   ContextMenuInfo menuInfo) {
  // TODO Auto-generated method stub
  if(v.getId()==R.id.TV01)
  {
   menu.add(&quot;Menu 1&quot;);
   menu.add(&quot;Menu 2&quot;);
   menu.add(&quot;Menu 3&quot;);
  }
  if(v.getId()==R.id.chronometer1)
  {
   menu.add(&quot;Start&quot;);
   menu.add(&quot;Stop&quot;);
   menu.add(&quot;Restart&quot;);
   menu.setHeaderIcon(android.R.drawable.ic_media_play);
   menu.setHeaderTitle(&quot;Timer....&quot;);
  }
  
  super.onCreateContextMenu(menu, v, menuInfo);
 }
    
}
&lt;/pre&gt;
&lt;li&gt;When you click on TextView &amp;amp; Chronotmeter that will simply display following Menu respectively. not perform any activity &lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisUPfisd7bBxuKGbvmdD6p7VXBV23DoFxar6yT7h5JCQZryCR2ixIVgKuvj9M6-6PUQt9vK5mANzIHOdu8cZimqG8x39E363p3o7NIQFLrd5x9pmO-BTid2t3et93ntnlqZlOum3H2rpkD/s1600/contextmenu11.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisUPfisd7bBxuKGbvmdD6p7VXBV23DoFxar6yT7h5JCQZryCR2ixIVgKuvj9M6-6PUQt9vK5mANzIHOdu8cZimqG8x39E363p3o7NIQFLrd5x9pmO-BTid2t3et93ntnlqZlOum3H2rpkD/s320/contextmenu11.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI8SFMsQ7hotoMBSLx_AmcnrMgqVliSBnKjWunVDho9GnJfTukphgGZTPOvgplZzWtyWsdnsWj6RwNfAprsLIWQ2H56XSV1bD2BGYIKJHvQVrsqSeRxIALuB9gq7rZJKY1LoHvPkbUwxL1/s1600/contextmenu12.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhI8SFMsQ7hotoMBSLx_AmcnrMgqVliSBnKjWunVDho9GnJfTukphgGZTPOvgplZzWtyWsdnsWj6RwNfAprsLIWQ2H56XSV1bD2BGYIKJHvQVrsqSeRxIALuB9gq7rZJKY1LoHvPkbUwxL1/s320/contextmenu12.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisUPfisd7bBxuKGbvmdD6p7VXBV23DoFxar6yT7h5JCQZryCR2ixIVgKuvj9M6-6PUQt9vK5mANzIHOdu8cZimqG8x39E363p3o7NIQFLrd5x9pmO-BTid2t3et93ntnlqZlOum3H2rpkD/s1600/contextmenu11.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZfE9d44ABk3ksXy6dPI1UPJtuIpGxGmMMyHPb1GCgu1h7E23oLhpQoqpXEjBvKnvhFRulrQXvdNHDXY3pd0CKubrwphBjo2RE9lw_JZJy5jvHrjl9_4Ht8x8dpvXM8qPA2qp9jmWMyRoB/s1600/contextmenu13.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZfE9d44ABk3ksXy6dPI1UPJtuIpGxGmMMyHPb1GCgu1h7E23oLhpQoqpXEjBvKnvhFRulrQXvdNHDXY3pd0CKubrwphBjo2RE9lw_JZJy5jvHrjl9_4Ht8x8dpvXM8qPA2qp9jmWMyRoB/s320/contextmenu13.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/2931326078019010729/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-context-menu-example.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/2931326078019010729'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/2931326078019010729'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-context-menu-example.html' title='Android Context Menu - Example '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEisUPfisd7bBxuKGbvmdD6p7VXBV23DoFxar6yT7h5JCQZryCR2ixIVgKuvj9M6-6PUQt9vK5mANzIHOdu8cZimqG8x39E363p3o7NIQFLrd5x9pmO-BTid2t3et93ntnlqZlOum3H2rpkD/s72-c/contextmenu11.png" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-8435285800608972636</id><published>2012-08-28T12:38:00.001+05:30</published><updated>2012-08-29T17:07:10.973+05:30</updated><title type='text'>Android All type of Built In Dialog Demo - Examples</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This example include the following types of dialogs as follows&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Alert Dialog Demo&lt;/li&gt;
&lt;li&gt;List Dialog Demo&lt;/li&gt;
&lt;li&gt;Progress Dialog Demo&lt;/li&gt;
&lt;li&gt;DatePicker Dialog Demo&lt;/li&gt;
&lt;li&gt;Character Picker Dialog Demo&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 align=&quot;center&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0N3ZSRkZjTWRBeHc&quot; target=&quot;_blank&quot;&gt;Download Android All Dialog Demo :Example Code&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;ol start=&quot;1&quot; style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;main.xml for this Project which Contain 5 button to call each Dialog
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;fill_parent&quot;
    &amp;gt;
&amp;lt;TextView  
    android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;@string/hello&quot;
    android:id=&quot;@+id/tvShow&quot;
    /&amp;gt;
    &amp;lt;Button android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;Alert Dialog&quot;
    android:id=&quot;@+id/btnAlert&quot; 
    /&amp;gt;
    
    &amp;lt;Button android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;List Dialog&quot;
    android:id=&quot;@+id/btnList&quot; 
    /&amp;gt;
    
    &amp;lt;Button android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;DatePicker Dialog&quot;
    android:id=&quot;@+id/btnDtPicker&quot; 
    /&amp;gt;
    
    &amp;lt;Button android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;Progress Dialog&quot;
    android:id=&quot;@+id/btnProgress&quot; 
    /&amp;gt;
    
    &amp;lt;Button android:layout_width=&quot;fill_parent&quot; 
    android:layout_height=&quot;wrap_content&quot; 
    android:text=&quot;Character Picker Dialog&quot;
    android:id=&quot;@+id/btnChPicker&quot; 
    /&amp;gt;
    
&amp;lt;/LinearLayout&amp;gt;
&amp;nbsp;&lt;/pre&gt;
&lt;div&gt;
&lt;ol start=&quot;2&quot; style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Following Java Code which will display different DialogBox&amp;nbsp; when you call them using clicking Buttons. they are create as follows..&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;brush: java&quot;&gt; 
package com.widget;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.text.method.CharacterPickerDialog;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AllDialogActivity extends Activity {
 /** Called when the activity is first created. */
 TextView tv;
 Button btnAlert, btnList, prgDilog = null, btnDtPicker, btnChButton;
 int year, month, day;
 CharacterPickerDialog cpd;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  tv = (TextView) findViewById(R.id.tvShow);
  cpd_init();
  /********
   * Alert Dialog Demo
   **********/
  btnAlert = (Button) findViewById(R.id.btnAlert);
  btnAlert.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v) {
    // TODO Auto-generated method stub
    AlertDialog.Builder builder = new AlertDialog.Builder(
      AllDialogActivity.this);

    builder.setMessage(&quot;Are you Sure you want to Exit?&quot;);
    builder.setCancelable(false);
    builder.setPositiveButton(&quot;Yes&quot;,
      new DialogInterface.OnClickListener() {

       public void onClick(DialogInterface dialog,
         int which) {
        // TODO Auto-generated method stub
        AllDialogActivity.this.finish();
       }
      });

    builder.setNegativeButton(&quot;No&quot;,
      new DialogInterface.OnClickListener() {

       public void onClick(DialogInterface dialog,
         int which) {
        // TODO Auto-generated method stub
        dialog.cancel();
       }
      });

    AlertDialog alert = builder.create();
    alert.show();
   }
  });
  /********
   * List Dialog Demo
   **********/
  btnList = (Button) findViewById(R.id.btnList);
  btnList.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v) {
    // TODO Auto-generated method stub
    AlertDialog.Builder builder = new AlertDialog.Builder(
      AllDialogActivity.this);

    CharSequence[] items = { &quot;Red&quot;, &quot;Green&quot;, &quot;Blue&quot; };
    builder.setTitle(&quot;Chose Color..&quot;);
    builder.setItems(items, new DialogInterface.OnClickListener() {

     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
      switch (which) {
      case 0:
       tv.setTextColor(Color.RED);
       break;
      case 1:
       tv.setTextColor(Color.GREEN);
       break;
      case 2:
       tv.setTextColor(Color.BLUE);
       break;
      }
     }
    });

    AlertDialog alert = builder.create();
    alert.show();
   }
  });

  /********
   * Progress Dialog Demo
   **********/
  prgDilog = (Button) findViewById(R.id.btnProgress);
  prgDilog.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v) {
    // TODO Auto-generated method stub
    final ProgressDialog myProgressDialog = ProgressDialog.show(
      AllDialogActivity.this, &quot;Please wait...(5sec)&quot;,
      &quot;Doing Extreme Calculations...&quot;, true);

    new Thread() {
     public void run() {
      try {
       // Do some Fake-Work
       sleep(5000);
      } catch (Exception e) {
      }
      // Dismiss the Dialog
      myProgressDialog.dismiss();
     }
    }.start();
   }
  });

  /********
   * DatePicker Dialog Demo
   **********/
  btnDtPicker = (Button) findViewById(R.id.btnDtPicker);
  btnDtPicker.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v) {
    // TODO Auto-generated method stub

    showDialog(0);
   }
  });

  /********
   * Character Picker Dialog Demo
   **********/
  btnChButton = (Button) findViewById(R.id.btnChPicker);
  btnChButton.setOnClickListener(new View.OnClickListener() {

   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    cpd_init();
    cpd.show();
   }
  });

 }

 //*** Overrided for Intialize DatePicker Dialog***/
 @Override
 protected Dialog onCreateDialog(int id) {
  Calendar c = Calendar.getInstance();
  year = c.get(Calendar.YEAR);
  month = c.get(Calendar.MONTH);
  day = c.get(Calendar.DAY_OF_MONTH);
  // TODO Auto-generated method stub
  switch (id) {
  case 0:
   return new DatePickerDialog(AllDialogActivity.this,
     datePickerListener, year, month, day);
  }
  return new DatePickerDialog(AllDialogActivity.this, datePickerListener,
    year, month, day);
 }

 //**** DatePicker Set Listener which call when we click on Set Button ****//
 private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {

  // when dialog box is closed, below method will be called.
  public void onDateSet(DatePicker view, int selectedYear,
    int selectedMonth, int selectedDay) {

   year = selectedYear;
   month = selectedMonth;
   day = selectedDay;

   // set selected date into textview
   tv.setText(new StringBuilder().append(day).append(&quot;-&quot;)
     .append(month + 1).append(&quot;-&quot;).append(year).append(&quot; &quot;));

   // set selected date into datepicker also
   // dpResult.init(year, month, day, null);

  }
 };

 // Character Picker Dialog initialization
 void cpd_init() {
  EditText et = new EditText(this);
  et.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
  final String options = &quot;0123456789ABCDEF&quot;;
  cpd = new CharacterPickerDialog(this, new View(this), null, options,
    false) {
   public void onClick(View v) {
    tv.setText(&quot;????:&quot;+((Button)v).getText().toString());
    dismiss();
   }
  };

 }

}&amp;nbsp;&lt;/pre&gt;
&lt;div&gt;
&lt;h4&gt;
The Execution of Code as follows..&lt;/h4&gt;
Initially Run the Project display the following Screen...&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/AVvXsEj6XlvoTDZmqKOLcAXegukp6Qb0RMYGK-RoIO1EvmMGCUdBKR3tXzprWtfwR1CvMzhThFSDa_XH5yXA_NKTAmt2OEplJLU0f36ax7nkjelgtssia3rmwEWeF8RzRq7jlPUI_LS8ojk-aBZF/s1600/alldialog1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6XlvoTDZmqKOLcAXegukp6Qb0RMYGK-RoIO1EvmMGCUdBKR3tXzprWtfwR1CvMzhThFSDa_XH5yXA_NKTAmt2OEplJLU0f36ax7nkjelgtssia3rmwEWeF8RzRq7jlPUI_LS8ojk-aBZF/s320/alldialog1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;Then When You Click on &quot;Alert Dialog&quot; Button that will show the following Dialog which ask for &quot;Are you Sure you want to Exit&quot; if you Press &quot;Yes&quot; than you will exit from this apps and if you say &quot;No&quot; than you will continue with this apps..&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/AVvXsEiL6dYnB69_GRPuelKSQeEBsm8KjWX3e3ZaRqRZK8g6XTtW1xfAUJN-WsMkOtbW16JAIFvXmPmnvRHPJB8ysTn3Bxmx1d9y-h4OCX8Hd4Oi6GMXmhoyE3QegoC3YVGtxHMvcPsx-9EIWydR/s1600/alldialog2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL6dYnB69_GRPuelKSQeEBsm8KjWX3e3ZaRqRZK8g6XTtW1xfAUJN-WsMkOtbW16JAIFvXmPmnvRHPJB8ysTn3Bxmx1d9y-h4OCX8Hd4Oi6GMXmhoyE3QegoC3YVGtxHMvcPsx-9EIWydR/s320/alldialog2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;This dialog Box will appears when you click on &quot;List Dialog&quot;&amp;nbsp; Button that ask you to Select any Color when you chose any color that Color will be set as Text color of TextView above displayed&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/AVvXsEgtkWdA8IygyRboRvcvXwkobwOoXibjKxRZFV4fLh8A3gVJmrDAJA573pUx9SC_eOuG6b0xoytBmQUgWcPxnTrqn9RfJp615t1otz4efe8Atc6WkKVbp9ufOCYCMUjbYsHZQnXKwNxnM_1n/s1600/alldialog3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtkWdA8IygyRboRvcvXwkobwOoXibjKxRZFV4fLh8A3gVJmrDAJA573pUx9SC_eOuG6b0xoytBmQUgWcPxnTrqn9RfJp615t1otz4efe8Atc6WkKVbp9ufOCYCMUjbYsHZQnXKwNxnM_1n/s320/alldialog3.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;This dialog box allows you to Select a date when you select date and say &quot;Set&quot; that Date date set in TextView.&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/AVvXsEjzr919D4-zotzCPf5w_clbvxpcHPSUAUB3VQhhstpNuwZnsG_rwoIwk-h8pgrovJnoBo9Rm5to5xHRoojXWp5sJAhIWsYHa2IYWpLFMqsBH3naIA4x9o2iph7wD5qZqzIIq-h2whcFfrgH/s1600/alldialog4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzr919D4-zotzCPf5w_clbvxpcHPSUAUB3VQhhstpNuwZnsG_rwoIwk-h8pgrovJnoBo9Rm5to5xHRoojXWp5sJAhIWsYHa2IYWpLFMqsBH3naIA4x9o2iph7wD5qZqzIIq-h2whcFfrgH/s320/alldialog4.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;This Progress Dialog box will simple wait for 5sec you can not perform any activity during this time and you can not cancel this dialog.&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/AVvXsEiTIc5PgNxuK7Zcc9mAqh38Ewq5-VePKnDg7MgYdyzefD4eHioRPjQ1mhWhEzw6Dg3BQ4ghN66Emof-S49KSrQ0nCgjUM27SnSWGoFTslwf6SRgWneYLw7xWsGL7WEvxAWWKtVv0wTA2NNJ/s1600/alldialog5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTIc5PgNxuK7Zcc9mAqh38Ewq5-VePKnDg7MgYdyzefD4eHioRPjQ1mhWhEzw6Dg3BQ4ghN66Emof-S49KSrQ0nCgjUM27SnSWGoFTslwf6SRgWneYLw7xWsGL7WEvxAWWKtVv0wTA2NNJ/s320/alldialog5.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&amp;nbsp;This dialog Allows to you to Select any Character From this..&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/AVvXsEgbnf3JbSrSFsCubIHh2PRmYA8rSnZIQhVT7HfIEVbc1K38d0Q1CqUBJcoa1hBsp7M6-CjofG4-_mcEOfc3wHYfpPkreoxtivaw5DPlA4uzMAVYvagABHHGU1kTMH7BPIFzwxdKYJ11QvpI/s1600/alldialog6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbnf3JbSrSFsCubIHh2PRmYA8rSnZIQhVT7HfIEVbc1K38d0Q1CqUBJcoa1hBsp7M6-CjofG4-_mcEOfc3wHYfpPkreoxtivaw5DPlA4uzMAVYvagABHHGU1kTMH7BPIFzwxdKYJ11QvpI/s320/alldialog6.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/8435285800608972636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-all-type-of-built-in-dialog.html#comment-form' title='32 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/8435285800608972636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/8435285800608972636'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-all-type-of-built-in-dialog.html' title='Android All type of Built In Dialog Demo - Examples'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEj6XlvoTDZmqKOLcAXegukp6Qb0RMYGK-RoIO1EvmMGCUdBKR3tXzprWtfwR1CvMzhThFSDa_XH5yXA_NKTAmt2OEplJLU0f36ax7nkjelgtssia3rmwEWeF8RzRq7jlPUI_LS8ojk-aBZF/s72-c/alldialog1.png" height="72" width="72"/><thr:total>32</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-7893280631094910624</id><published>2012-08-22T17:19:00.001+05:30</published><updated>2012-08-29T16:53:33.855+05:30</updated><title type='text'>Android Option Menu using Xml file: How Create with Example </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
First we will create Simple Option&amp;nbsp; menus as Follows Steps&lt;br /&gt;
&lt;br /&gt;
&lt;h2 align=&quot;center&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0TmFYbE5RQkJuMmc&quot; target=&quot;_blank&quot;&gt;Download Android Option Menu with Xml file: Project&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Create
a new Android Project Name &lt;/span&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% silver; color: black; font-size: 10pt; line-height: 115%;&quot;&gt;MenuDemo&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 14px;&quot;&gt;Add XML file into res/menus/menu.xml for that follow the following Steps&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 14px;&quot;&gt;Right Click on Project Folder&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 14px;&quot;&gt;Select New&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 14px;&quot;&gt;Select &quot;Android XML file&quot;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 14px;&quot;&gt;Give name of file As &quot;menus&quot;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 14px;&quot;&gt;Select &quot;menu&quot; type of Resource.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 14px;&quot;&gt;Say Finish.&lt;br /&gt;Add the Following code.....&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;pre class=&quot;brush: xml&quot;&gt;&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    &lt;item android:icon=&quot;@drawable/d&quot; android:id=&quot;@+id/item1&quot; android:title=&quot;Hello&quot;&gt;&lt;/item&gt;
    &lt;item android:icon=&quot;@drawable/e&quot; android:id=&quot;@+id/item2&quot; android:title=&quot;New Activity&quot;&gt;&lt;/item&gt;
    &lt;item android:icon=&quot;@drawable/f&quot; android:id=&quot;@+id/item3&quot; android:title=&quot;Dial&quot;&gt;&lt;/item&gt;
&lt;/menu&gt;


&lt;/pre&gt;
&lt;/div&gt;
&lt;ol start=&quot;3&quot; style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-size: 11pt; line-height: 115%;&quot;&gt;Override
the onCreateOptionMenu() Method in the Activity class files where you want to
add menu. From&amp;nbsp; &lt;/span&gt;&lt;br /&gt;



&lt;ul&gt;
&lt;li&gt;Right click in Activity file&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font: 7pt &amp;quot;Times New Roman&amp;quot;;&quot;&gt;\&lt;/span&gt;Select ”Source”&lt;/li&gt;
&lt;li&gt;Select “Override / Implement Methods “&lt;/li&gt;
&lt;li&gt;Select “onCreateOptionMenu()” method &lt;/li&gt;
&lt;li&gt;Say Ok. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 15px; line-height: 17px;&quot;&gt;We will Use MenuInflater class to show the menus by put following code in&amp;nbsp;&lt;/span&gt;onCreateOptionMenu()&lt;br /&gt;
&lt;pre class=&quot;brush: java&quot;&gt;@Override
public boolean onCreateOptionsMenu(Menu menu) {
 MenuInflater mi = getMenuInflater();
 mi.inflate(R.menu.menus, menu);
 return super.onCreateOptionsMenu(menu);
}
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;We will Interact with the menu Item as follows using onOptionsItemSelected() method.&amp;nbsp;
&lt;pre class=&quot;brush: java&quot;&gt;@Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
  switch (item.getItemId()) {
  case R.id.item1:
   Toast.makeText(getApplicationContext(), &quot;Hello!&quot;, 5).show();
   break;
  case R.id.item2:
   Intent i = new Intent(getApplicationContext(), ActivityA.class);
   startActivity(i);
   break;
  case R.id.item3:
   Intent dial = new Intent(Intent.ACTION_DIAL);
   startActivity(dial);
   break;
  default:
   break;
  }
  return super.onOptionsItemSelected(item);
 }
&lt;/pre&gt;
&lt;br /&gt;
Where We have done following actions Menu wise....&lt;br /&gt;&lt;b&gt;Item1 :&lt;/b&gt; We wiill Display Toast &quot;Hello&quot;&lt;br /&gt;&lt;b&gt;Item2 : &lt;/b&gt;We call the New Activity &quot;Activity A&quot;&lt;br /&gt;&lt;b&gt;Item3 : &lt;/b&gt;We display the Default Dialer of Android.&lt;/li&gt;
&lt;li&gt;Run the Android Apps&lt;/li&gt;
&lt;/ol&gt;
You can Interact with Menu by clicking on all Menu Item&amp;nbsp;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;First Click on Menu Button of Device as follows..&lt;/li&gt;
&lt;li&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/AVvXsEhHHRwwgE6Nsb_s7ILMn49MnCqiLbXBiscZces-OAj3dqBaQk35p_o1T8DxQGcVDpFv5a3vJieRVi09sqVkWQdpTjcHtPAOMLHr-XtiNVJwTto3p4PAHB_hKxWI2_311JDKHYBYyqcWaeI7/s1600/xmlmenumenu.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHHRwwgE6Nsb_s7ILMn49MnCqiLbXBiscZces-OAj3dqBaQk35p_o1T8DxQGcVDpFv5a3vJieRVi09sqVkWQdpTjcHtPAOMLHr-XtiNVJwTto3p4PAHB_hKxWI2_311JDKHYBYyqcWaeI7/s1600/xmlmenumenu.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;That will display the following screen as follows&amp;nbsp;&lt;/li&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/AVvXsEjjjy_qSBbfsg1DhKB3oaE_aqpBJ1OBPbyJBMRvzaqCflcUqkHpl28CHImlnsxkiSAlhhvKTIwEkHDsGUkNLNutx6BrvQ8037Isw7Ac4pvP2W7p49_PQteuIYwfDMnb6bL-EZNocN_Jdt2i/s1600/xmlmenu1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjjy_qSBbfsg1DhKB3oaE_aqpBJ1OBPbyJBMRvzaqCflcUqkHpl28CHImlnsxkiSAlhhvKTIwEkHDsGUkNLNutx6BrvQ8037Isw7Ac4pvP2W7p49_PQteuIYwfDMnb6bL-EZNocN_Jdt2i/s320/xmlmenu1.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;li&gt;Press On the &quot;Hello&quot; that will show you Following Screen..&amp;nbsp;&lt;/li&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/AVvXsEhZrvFeQqLZ-QL2OWmxuS0mIP1fGJ-e8g9qWrLh-STffYazwNvYYIZqvYEyK-8-bZrgLURt1d0U0EABJAm6GsLH4fMgQzr4d4Q-EhL_bpsxEupNHyOAfIU-d-49uOLg0acP8ljbIfYB4rio/s1600/xmlmenu2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZrvFeQqLZ-QL2OWmxuS0mIP1fGJ-e8g9qWrLh-STffYazwNvYYIZqvYEyK-8-bZrgLURt1d0U0EABJAm6GsLH4fMgQzr4d4Q-EhL_bpsxEupNHyOAfIU-d-49uOLg0acP8ljbIfYB4rio/s320/xmlmenu2.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;li&gt;Then Again Press Menu Button Click on &quot;New Activity&quot; Item&lt;/li&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/AVvXsEjN0QUkq5KLLF8c8cwoGv9XGww7pWIWXgAlyPRuEFSPDMu9fa28HfuEfz2O8oUmQk3h8udKt4dsHtjfGxHzh8OfaVW036H5Dc427zFaTIUE2oit9i0FY0iMmUSm7sns3CS_0FKrsd2haU4V/s1600/xmlmenu3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjN0QUkq5KLLF8c8cwoGv9XGww7pWIWXgAlyPRuEFSPDMu9fa28HfuEfz2O8oUmQk3h8udKt4dsHtjfGxHzh8OfaVW036H5Dc427zFaTIUE2oit9i0FY0iMmUSm7sns3CS_0FKrsd2haU4V/s320/xmlmenu3.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;li&gt;Then Press Back Button. Then Again Click on &quot;Dial&quot; Item. that shows following Dialer.&lt;/li&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/AVvXsEgN7bIhjcxEfaxtedHMOBZ9uRnfxih4K6hVBTqE4mEltnt4ZvAeYT5nK8akApvp6-FgowJAmCkIzQzoGWmBipKfLh5peoUdBItMXUV70D4W5-Brlb_P7GXUXzNa_PyD1FqevAjipyZOccTr/s1600/xmlmenu4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN7bIhjcxEfaxtedHMOBZ9uRnfxih4K6hVBTqE4mEltnt4ZvAeYT5nK8akApvp6-FgowJAmCkIzQzoGWmBipKfLh5peoUdBItMXUV70D4W5-Brlb_P7GXUXzNa_PyD1FqevAjipyZOccTr/s320/xmlmenu4.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/ul&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/7893280631094910624/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-option-menu-using-xml-file-how.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/7893280631094910624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/7893280631094910624'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-option-menu-using-xml-file-how.html' title='Android Option Menu using Xml file: How Create with Example '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEhHHRwwgE6Nsb_s7ILMn49MnCqiLbXBiscZces-OAj3dqBaQk35p_o1T8DxQGcVDpFv5a3vJieRVi09sqVkWQdpTjcHtPAOMLHr-XtiNVJwTto3p4PAHB_hKxWI2_311JDKHYBYyqcWaeI7/s72-c/xmlmenumenu.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4980586312959306498.post-3043583818425919288</id><published>2012-08-22T16:09:00.001+05:30</published><updated>2012-08-22T17:25:52.523+05:30</updated><title type='text'>Android Option Menu: How Create with Example </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
First we will create Simple Option&amp;nbsp; menus as Follows Steps&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;a href=&quot;https://docs.google.com/open?id=0B876sLO8DGo0bWF5MjNNOXFtWFU&quot; target=&quot;_blank&quot;&gt;Download Android Option Menu: Project&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11pt; line-height: 115%;&quot;&gt;Create
a new Android Project Name &lt;/span&gt;&lt;span style=&quot;background: none repeat scroll 0% 0% silver; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt; line-height: 115%;&quot;&gt;MenuDemoWithoutXml&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11pt; line-height: 115%;&quot;&gt;Override
the onCreateOptionMenu() Method in the Activity class files where you want to
add menu. From&amp;nbsp; &lt;/span&gt;&lt;br /&gt;



&lt;ul&gt;
&lt;li&gt;Right click in Activity file&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Wingdings;&quot;&gt;&lt;span style=&quot;font: 7pt &amp;quot;Times New Roman&amp;quot;;&quot;&gt;\&lt;/span&gt;&lt;/span&gt;Select ”Source”&lt;/li&gt;
&lt;li&gt;Select “Override / Implement Methods “&lt;/li&gt;
&lt;li&gt;Select “onCreateOptionMenu()” method &lt;/li&gt;
&lt;li&gt;Say Ok. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11pt; line-height: 115%;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11pt; line-height: 115%;&quot;&gt;Adding
Menu Items into by following code&lt;/span&gt;&lt;/li&gt;
&lt;pre class=&quot;brush: java&quot;&gt;package com.menu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;

public class MenuDemoWithoutXmlActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // TODO Auto-generated method stub
  menu.add(&quot;Item 1&quot;).setIcon(android.R.drawable.btn_dialog)
    .setIntent(new Intent(this, ActivityA.class));
  menu.add(&quot;Item 2&quot;).setIcon(android.R.drawable.btn_minus);
  menu.add(&quot;Item 3&quot;).setIcon(android.R.drawable.btn_star_big_off);
  return super.onCreateOptionsMenu(menu);
 }
}&lt;/pre&gt;
&lt;pre class=&quot;brush: java&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;/ol&gt;
This Code will just display the Simple Menu they have not any effect&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/AVvXsEhS6jp9pT9-Kk-A3qk5mNLto9sNGeHO964hRr1QT2jsCht1Su-hgvPJ5vqDU5d1AEYaeJ30Nt2vyD4ruwGi29gT30_t9n-50Tg_SCH3oLN_7vR8aocX7abH7wjO0cGZKa3Lf4NE3pMJQ9IJ/s1600/simplemenu.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS6jp9pT9-Kk-A3qk5mNLto9sNGeHO964hRr1QT2jsCht1Su-hgvPJ5vqDU5d1AEYaeJ30Nt2vyD4ruwGi29gT30_t9n-50Tg_SCH3oLN_7vR8aocX7abH7wjO0cGZKa3Lf4NE3pMJQ9IJ/s320/simplemenu.png&quot; width=&quot;213&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
For more Menu with Action we will see in following posts:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;a href=&quot;http://androidwid.blogspot.in/2012/08/android-option-menu-using-xml-file-how.html&quot; target=&quot;_blank&quot;&gt;Android Option Menu using Xml file: How Create with Example&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Grouping the Menu Item Why&amp;nbsp;Required&amp;nbsp;to Group.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Android Content Menu using XML file : How Create With Example.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://androidwid.blogspot.com/feeds/3043583818425919288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-option-menu-how-create-with.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/3043583818425919288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4980586312959306498/posts/default/3043583818425919288'/><link rel='alternate' type='text/html' href='http://androidwid.blogspot.com/2012/08/android-option-menu-how-create-with.html' title='Android Option Menu: How Create with Example '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/11739190683775521350</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/AVvXsEhS6jp9pT9-Kk-A3qk5mNLto9sNGeHO964hRr1QT2jsCht1Su-hgvPJ5vqDU5d1AEYaeJ30Nt2vyD4ruwGi29gT30_t9n-50Tg_SCH3oLN_7vR8aocX7abH7wjO0cGZKa3Lf4NE3pMJQ9IJ/s72-c/simplemenu.png" height="72" width="72"/><thr:total>1</thr:total></entry></feed>