Loading...

Simple Pop up Menu - Android

View: 180    Dowload: 0   Comment: 0   Post by: daii   Category: Mobile applications   Fields: Game - Entertainment

Download  simple-pop-up-menu-android.zip (522.63 KB)

You need to Sign In to download the file simple-pop-up-menu-android.zip
If you do not have an account then Sign up for free here

In this tutorial we will try to create a Simple Pop Up Menu using Android. This simple app can be used when choosing a list and display its value. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any devices such as TV, phones, watches etc. So now let's do the coding.....

Getting Started:

First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things.

Here's the link for the Android Studio https://developer.android.com/studio/index.html.

Layout Design

We will now create the design for the application, first locate the layout file called activity_main.xml, this is the default name when create a new activity. Then write these codes inside your layout file.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> xmlns:app="<a href="http://schemas.android.com/apk/res-auto"
  5. " rel="nofollow">http://schemas.android.com/apk/res-auto"
  6. </a> xmlns:tools="<a href="http://schemas.android.com/tools"
  7. " rel="nofollow">http://schemas.android.com/tools"
  8. </a> android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. tools:context="com.razormist.simplepopupmenu.MainActivity">
  11.  
  12. <TextView
  13. android:id="@+id/tv_title"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:text="What is your favorite Programming Language"
  17. android:layout_centerHorizontal="true"
  18. android:textSize="30dp"
  19. android:layout_marginTop="150dp"
  20. android:gravity="center"/>
  21. android:id="@+id/btn_change"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:layout_centerHorizontal="true"
  25. android:layout_marginTop="20dp"
  26. android:layout_below="@+id/tv_title"
  27. android:text="Select an option" />
  28. </RelativeLayout>

Android Manifest File

The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code. It describe the overall information about the application. It contains some libraries that needed to access the several method within the app.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="<a href="http://schemas.android.com/apk/res/android"
  3. " rel="nofollow">http://schemas.android.com/apk/res/android"
  4. </a> package="com.razormist.simplepopupmenu">
  5.  
  6. <application
  7. android:allowBackup="true"
  8. android:icon="@mipmap/ic_launcher"
  9. android:label="@string/app_name"
  10. android:roundIcon="@mipmap/ic_launcher_round"
  11. android:supportsRtl="true"
  12. android:theme="@style/AppTheme">
  13. <activity android:name=".MainActivity"
  14. android:configChanges="orientation"
  15. android:screenOrientation="portrait">
  16. <intent-filter>
  17. <action android:name="android.intent.action.MAIN" />
  18.  
  19. <category android:name="android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </activity>
  22. </application>
  23. </manifest>

Creating the List

This is where we store the list of all the data that we need. To do this right click on the resselect new the choose directory. After that create a new xml file namely programming.xml inside the newly created directory. Then write these block of codes inside the file.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <menu xmlns:android="<a href="http://schemas.android.com/apk/res/android">
  3. " rel="nofollow">http://schemas.android.com/apk/res/android">
  4. </a> <item
  5. android:id="@+id/c"
  6. android:title="C" />
  7. <item
  8. android:id="@+id/cplus"
  9. android:title="C++" />
  10. <item
  11. android:id="@+id/csharp"
  12. android:title="C#" />
  13. <item
  14. android:id="@+id/java"
  15. android:title="Java" />
  16. <item
  17. android:id="@+id/php"
  18. android:title="PHP" />
  19. <item
  20. android:id="@+id/vb"
  21. android:title="VB" />
  22. <item
  23. android:id="@+id/python"
  24. android:title="Python" />
  25. <item
  26. android:id="@+id/ruby"
  27. android:title="Ruby" />
  28. </menu>

The Main Function

This code contains the main function of the application. This code will display the data within the external xml file to display inside the button property. To start with first locate your MainActivity java file and open it, then write this variable inside the MainActivity class.

  1. Button btn_change;

Finally, write these block of codes inside the onCreate method to run the application.

  1. btn_change = (Button)findViewById(R.id.btn_change);
  2.  
  3. btn_change.setOnClickListener(new View.OnClickListener() {
  4. @Override
  5. public void onClick(View v) {
  6. PopupMenu popupMenu = new PopupMenu(MainActivity.this, btn_change);
  7. popupMenu.getMenuInflater().inflate(R.menu.programming, popupMenu.getMenu());
  8. popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
  9. @Override
  10. public boolean onMenuItemClick(MenuItem item){
  11. Toast.makeText(MainActivity.this, "I Like " + item.getTitle(), Toast.LENGTH_SHORT).show();
  12. return true;
  13. }
  14. });
  15.  
  16. popupMenu.show(); }
  17. });

Try to run the app and see if it worked.

There you have it we have created a Simple Pop up Menu using Android. I hope that this tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Simple Pop up Menu - Android

Learn on how to create a Simple Pop Up Menu using Android. This simple app can be used when choosing a list and display its value. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any devices such as TV, phones, watches etc.

Posted on 06-03-2018 

Comment:

To comment you must be logged in members.

Files with category

  • How to Display a Battery Charge Level in Xamarin Forms using Font Awesome

    How to Display a Battery Charge Level in Xamarin Forms using Font Awesome

    View: 80    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Other

    I was building a Xamarin Forms application with an interface that displays the charge level of a battery. I choose to do it with Font Awesome to give uniform aspect to this application with the website the same product has.

  • 8-bit LED Binary Counter

    8-bit LED Binary Counter

    View: 93    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Other

    This article offers a simple implementation of the binary counter powered by Raspberry PI3 and 8 LEDs. It is very similar to what was done before for Arduino board in the previous article Connecting an Arduino to a Breadboard to Light Up LEDs. In...

  • Chat App

    Chat App

    View: 117    Download: 3   Comment: 0

    Category: Android     Fields: none

    This is a Chat App for Android mobile. You can make separate chat with you partner. I'm using Mysql Database and Php code and All APIs are develop on PHP (REST APIs). My whatsApp:+918285672453: Email ID: nirbhayiise@gmail.com

  • Tower Defense 3D

    Tower Defense 3D

    View: 109    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    The goal in this game is to protect your territory against the attacking enemies. Place defensive structures on or along their path of attack to prevent them reaching your base. Strategic choice and positioning of defensive elements is an essential...

  • Flap the Bird

    Flap the Bird

    View: 66    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    Tap your screen to make the bird fly. While you are flying there are destruction that will stop you. Avoid hitting the floor and flying to high this will deduct your life. You can collect coins and life along the way. For more mobile games and...

  • Bad Santa

    Bad Santa

    View: 87    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    This is a simple shooting game where the Bad Santa is shooting the bad snowman and reindeer. You can collect coins and life along the way. For more mobile games and tutorials you can visit this site.

  • Flappy Halloween Game

    Flappy Halloween Game

    View: 74    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    Flappy Halloween is a simple game, tap the screen to move the player. Shoot the pumpkin in the ring to gain score. Avoid hitting the flying destructions and falling from the ground. Since the Halloween is coming this game is really perfect to play...

  • Tilt Ball Game

    Tilt Ball Game

    View: 63    Download: 0   Comment: 0

    Category: Android     Fields: Game - Entertainment

    This game is simple you need to tilt your device to make the ball move in your own desired direction. Reach the finish line before the time ends and move to the next level.

 
File suggestion for you
Loading...
File top downloads
Loading...
Loading...
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd