Loading...

Simple Pop up Menu - Android

View: 232    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

  • Android - Simple Image Capture

    Android - Simple Image Capture

    View: 589    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Image Capture using Android. This simple application can be used to any system that needed the information about the location of the user. The android is an open source operating system it's free and user friendly to...

  • Android - Simple Video Player

    Android - Simple Video Player

    View: 441    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Video Player using Android. This simple application can be use in viewing some videos. The android is an open source operating system it's free and user friendly to mobile developers. Android is available to any...

  • An Experience about Using Webview in Android Studio 3.0

    An Experience about Using Webview in Android Studio 3.0

    View: 221    Download: 0   Comment: 0

    Category: Android     Fields: Other

    I am blogging on ngocminhtran.com (using WordPress platform). Like most websites, I want to write an Android application to help viewers have a lot of great experiences with my blog.

  • Android - Simple Sending SMS

    Android - Simple Sending SMS

    View: 502    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Sending SMS using Android. This tutorial is only an example for sending an SMS, it does not contain the receiving message yet. Android is a mobile operating system developed by Google. It used in several gadget like...

  • Bomb Explode! (An Android App Strategy Game)

    Bomb Explode! (An Android App Strategy Game)

    View: 453    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This android app named Bomb Explode! is a capstone project that I made for a particular school. BOMB EXPLODE! is a Human Versus Computer strategy game. The objective is to eliminate the opponent by blowing up their BOMBS. Each player takes a turn by...

  • GIS App for Flood-Prone and Disease Affected Areas

    GIS App for Flood-Prone and Disease Affected Areas

    View: 451    Download: 1   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    GIS App for Flood-Prone and Disease Affected Areas is one of the capstone project that I have created in a particular school. Features of the application: - Geographic Map - GIS - Flood Prone Map - Urban Map - Search a particular area - Has SQLite...

  • NSO Demographic Application

    NSO Demographic Application

    View: 492    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This app is entitled NSO Demographic Application that was one of the capstone project/thesis project that I made for a particular school. This app features to provide a demographic survey of the National Statistics Office that will send to the...

  • HandEBook: An IT Portable Book Application

    HandEBook: An IT Portable Book Application

    View: 464    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This is an android mobile application entitled HandEBook: An IT Portable Book Application was one one of the capstone project that I have made in our clients at Cotabato. We used the Basic4Android software for the frontend and SQLite for the database...

 
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