In this tutorial we learn how to write a program for create a Drop down menu in android.It also known as Popup Menu. the Drop down menu is a one types of menu like Context menu,Option Menu etc. they can be used for settings like Delete,Search,Copy,Pest,Rename,Move,More etc.In this example we see how to create simple Drop down menu in android that contains various menu items.
Let's do fun with code:
CREATE NEW PROJECT
We need:
1) main.xml located here ...res/menu
1) activity_main.xml
2) MainActivity.java
Step 1: Write code into main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
<item
android:id="@+id/one"
android:title="Rename"/>
<item
android:id="@+id/two"
android:title="Delete"/>
<item
android:id="@+id/three"
android:title="Copy"/>
</menu>
Step 2: write code into activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btclickme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>
Step 3: Write code into MainActivity.java
package dev.androidapplink.custommenuapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;
public class MainActivity extends Activity {
// create variable
Button btnclickme;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// load control
btnclickme = (Button) findViewById(R.id.btclickme);
btnclickme.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Create the instance of Menu
PopupMenu popup = new PopupMenu(MainActivity.this, btnclickme);
// Inflating menu using xml file
popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());
// registering OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(MainActivity.this,
"You Clicked : " + item.getTitle(),
Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
}
});
}
}
Step 4: Now Run Your Project:
Let's do fun with code:
CREATE NEW PROJECT
We need:
1) main.xml located here ...res/menu
1) activity_main.xml
2) MainActivity.java
Step 1: Write code into main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
<item
android:id="@+id/one"
android:title="Rename"/>
<item
android:id="@+id/two"
android:title="Delete"/>
<item
android:id="@+id/three"
android:title="Copy"/>
</menu>
Step 2: write code into activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btclickme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>
Step 3: Write code into MainActivity.java
package dev.androidapplink.custommenuapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupMenu;
import android.widget.Toast;
public class MainActivity extends Activity {
// create variable
Button btnclickme;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// load control
btnclickme = (Button) findViewById(R.id.btclickme);
btnclickme.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Create the instance of Menu
PopupMenu popup = new PopupMenu(MainActivity.this, btnclickme);
// Inflating menu using xml file
popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());
// registering OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(MainActivity.this,
"You Clicked : " + item.getTitle(),
Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();
}
});
}
}
Step 4: Now Run Your Project:
Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
ReplyDeleteAndroid Training in chennai
Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.
ReplyDeleteBlock chain training in bangalore
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeleteangularjs training in chennai
Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
ReplyDeleteBlueprism training in Chennai
Blueprism training in Bangalore
Blueprism training in Pune
Blueprism online training
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
ReplyDeleteDevops Training in Chennai
Devops Training in Bangalore
Devops Training in pune
I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
ReplyDeleteData Science Training in Chennai | Data Science course in anna nagar
Data Science course in chennai | Data science course in Bangalore
Data Science course in marathahalli | Data Science course in btm
Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
ReplyDeletejava training in chennai | java training in bangalore
java online training | java training in pune
Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
ReplyDeleteAWS Training in Toronto | Amazon Web Services Training in Toronto , Canada
AWS Training in New york city | Amazon Web Services in New York City
AWS Training in London | Amazon Web Services Training in London , UK
It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
ReplyDeleteangularjs-Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
angularjs-Training in sholinganallur
angularjs-Training in velachery
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
ReplyDeleteadvanced excel training in bangalore
Excellent content!!! After reading your blog, I am curious to read the next part of the blog.
ReplyDeleteSelenium Training in Chennai
Selenium Training
iOS Training in Chennai
Digital Marketing Training in Chennai
core java training in chennai
Selenium Interview Questions and Answers
Future of testing professional
French Classes in Chennai
French Courses in Chennai
Nice Blog
ReplyDeleteblockchain training in Bangalore
Just stumbled across your blog and was instantly amazed with all the useful information that is on it. Great post, just what i was looking for and i am looking forward to reading your other posts soon!
ReplyDeleteangularjs online training
apache spark online training
informatica mdm online training
devops online training
aws online training
After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training
I Got Job in my dream company with decent 12 Lacks Per Annum Salary, I have learned this world most demanding course out there in the current IT Market from the Data Science Course in Bangalore Providers who helped me a lot to achieve my dreams comes true. Really worth trying.
ReplyDeleteThanks for your Blogs Appreciating the persistence you put into your blog and detailed information you provide.
ReplyDeleteAws training chennai | AWS course in chennai
Rpa training in chennai | RPA training course chennai
oracle training chennai | oracle training in chennai
Hadoop Training in chennai | Hadoop training course in chennai
Visit for Blockchain training in Bangalore:
ReplyDeleteBlockchain training in Bangalore
Visit for Blockchain training in Bangalore:- Blockchain training in Bangalore
ReplyDeletenice blog thanks for sharing
ReplyDeleteAngularJS Training in Chennai | AngularJS Training in Anna Nagar | AngularJS Training in OMR | AngularJS Training in Porur | AngularJS Training in Tambaram | AngularJS Training in Velachery
Amazing post. Everything is helpful and efficient when I read your blog.
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
I am really feeling very happy to see your blog.good luck.nd thanks alot.
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
"nice blog and very interesting. . .
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
"
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...Keep to share!!
ReplyDeleteAndroid Training in Chennai | Certification | Mobile App Development Training Online | Android Training in Bangalore | Certification | Mobile App Development Training Online | Android Training in Hyderabad | Certification | Mobile App Development Training Online | Android Training in Coimbatore | Certification | Mobile App Development Training Online | Android Training in Online | Certification | Mobile App Development Training Online
Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
ReplyDeletedata science training in chennai
data science training in velachery
android training in chennai
android training in velachery
devops training in chennai
devops training in velachery
artificial intelligence training in chennai
artificial intelligence training in velachery
Thanks for your informative article, Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
ReplyDeleteAngular js Training in Chennai
Angular js Training in Velachery
Angular js Training in Tambaram
Angular js Training in Porur
Angular js Training in Omr
Angular js Training in Annanagar
The content here is really creative. Thanks for the insight. This really helps through my learning.
ReplyDeleteSelenium Training in Chennai
Selenium Training in Velachery
Selenium Training in Tambaram
Selenium Training in Porur
Selenium Training in Omr
Selenium Training in Annanagar
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
ReplyDeleteamazon web services aws training in chennai
microsoft azure training in chennai
workday training in chennai
android-training-in chennai
ios training in chennai
I am really feeling very happy to see your blog.good luck.nd thanks alot.
ReplyDeleteIELTS Coaching in chennai
German Classes in Chennai
GRE Coaching Classes in Chennai
TOEFL Coaching in Chennai
Spoken english classes in chennai | Communication training
good article
ReplyDeletethanks for sharing
data science training in chennai
ccna training in chennai
iot training in chennai
cyber security training in chennai
ethical hacking training in chennai
Thanks for such a wonderful content. Our Motive is not just to create links but to get them indexed as will
ReplyDeleteIncrease Domain Authority (DA).We’re on a mission to increase DA PA of your domain
High Quality Backlink Building Service
Boost DA upto 15+ at cheapest
Boost DA upto 25+ at cheapest . Very Helpful
ReplyDeleteYour courage in facing challenges is truly inspiring. You never back down from a difficult situation. Buy suit price in india from suit price in india
ReplyDeleteYoung discover writer situation new admit social.religious
ReplyDelete