<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>context menu in android Archives -</title>
	<atom:link href="https://mitindia.in/tag/context-menu-in-android/feed/" rel="self" type="application/rss+xml" />
	<link>https://mitindia.in/tag/context-menu-in-android/</link>
	<description></description>
	<lastBuildDate>Mon, 11 Jul 2016 11:36:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://mitindia.in/wp-content/uploads/2023/03/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>context menu in android Archives -</title>
	<link>https://mitindia.in/tag/context-menu-in-android/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Android Example to show Context Menu</title>
		<link>https://mitindia.in/android-example-to-show-context-menu/</link>
		
		<dc:creator><![CDATA[SKB]]></dc:creator>
		<pubDate>Tue, 28 Jun 2016 06:14:22 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[context menu in android]]></category>
		<guid isPermaLink="false">http://www.mitindia.in/?p=171</guid>

					<description><![CDATA[<p>Android Context menu example Following example shows that how to create context menu application using Android. Follow the below steps to create. a) copy the following code into activity_main.xml&#8221; file &#60;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&#62; &#60;TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView" android:textColor="#005599" android:textAlignment="center" android:textSize="16pt" /&#62; &#60;ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/listView1" android:layout_alignParentTop="true" android:layout_marginTop="53dp" [&#8230;]</p>
<p>The post <a href="https://mitindia.in/android-example-to-show-context-menu/">Android Example to show Context Menu</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Android Context menu example</h2>
<p>Following example shows that how to create context menu application using Android. Follow the below steps to create.</p>
<p>a) copy the following code into activity_main.xml&#8221; file</p>
<pre>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&gt;

    &lt;TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:textColor="#005599"
        android:textAlignment="center"
        android:textSize="16pt" /&gt;

    &lt;ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listView1"
        android:layout_alignParentTop="true"
        android:layout_marginTop="53dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" /&gt;

&lt;/RelativeLayout&gt;

b) Now copy the following code ito "MainActivity.java" file
package app.mitindia.com.contextmenu;

import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class MainActivity extends Activity {


    ListView listView1;
    String contacts[] = {"Ganesh", "Shiva", "Vishnu", "Rahim", "Paul"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView1 = (ListView) findViewById(R.id.listView1);
        ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, contacts);
        listView1.setAdapter(adapter);
        registerForContextMenu(listView1);

    }

    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.setHeaderTitle("Select the action");
        menu.add(0, v.getId(), 0, "Call");
        menu.add(0, v.getId(), 0, "SMS");
        menu.add(0, v.getId(), 0, "WhatsApp");
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        if (item.getTitle() == "Call") {
            Toast.makeText(getApplicationContext(), "Calling mode", Toast.LENGTH_LONG).show();

        } else if (item.getTitle() == "SMS") {
            Toast.makeText(getApplicationContext(), "Messaging mode", Toast.LENGTH_LONG).show();
        } else if (item.getTitle() == "WhatsApp") {
            Toast.makeText(getApplicationContext(), "Whats App mode", Toast.LENGTH_LONG).show();
        } else {
            return false;
        }
        return true;
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}</pre>
<pre>c) Run the application see the following output.</pre>
<p><img fetchpriority="high" decoding="async" class="alignnone" src="https://shivkblog.files.wordpress.com/2015/06/screenshot_2015-06-29-14-10-58.png?w=169" alt="Screenshot_2015-06-29-14-10-58" width="169" height="300" /></p>
<p>&nbsp;</p>
<p><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fmitindia.in%2Fandroid-example-to-show-context-menu%2F&amp;linkname=Android%20Example%20to%20show%20Context%20Menu" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fmitindia.in%2Fandroid-example-to-show-context-menu%2F&amp;linkname=Android%20Example%20to%20show%20Context%20Menu" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fmitindia.in%2Fandroid-example-to-show-context-menu%2F&#038;title=Android%20Example%20to%20show%20Context%20Menu" data-a2a-url="https://mitindia.in/android-example-to-show-context-menu/" data-a2a-title="Android Example to show Context Menu"><img src="https://static.addtoany.com/buttons/favicon.png" alt="Share"></a></p><p>The post <a href="https://mitindia.in/android-example-to-show-context-menu/">Android Example to show Context Menu</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
