Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Menu:
- ========
- MainActivity.java
- ==================
- package com.example.android.mymenu;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- Context context;
- ListView myList;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- }
- private void setPointer()
- {
- this.context=this;
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- //create MenuInflater object
- MenuInflater inflater=getMenuInflater();
- //inflate the menu
- inflater.inflate(R.menu.menu_main,menu);
- return super.onCreateOptionsMenu(menu);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId())
- {
- case R.id.itemMain:
- Toast.makeText(context, R.string.mainPage, Toast.LENGTH_SHORT).show();
- break;
- case R.id.itemAccess:
- Toast.makeText(context, R.string.accessPage, Toast.LENGTH_SHORT).show();
- Intent intent = new Intent(this,Accesories.class);
- //intent.putExtra("userName",getUser);
- startActivity(intent);
- finish();
- break;
- case R.id.itemInvite:
- Toast.makeText(context, R.string.invitePage, Toast.LENGTH_SHORT).show();
- break;
- case R.id.itemProf:
- Toast.makeText(context, R.string.profPage, Toast.LENGTH_SHORT).show();
- break;
- case R.id.itemSitting:
- Toast.makeText(context, R.string.sitPage, Toast.LENGTH_SHORT).show();
- break;
- /*//create Alert dialog builder to design Alert Dialog
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- //set the title
- builder.setTitle("About the application...");
- //creating a new view of TextView
- TextView txtView = new TextView(context);
- //setting text size
- txtView.setTextSize(60);
- //setting the text inside
- txtView.setText("Adam is the king!!!");
- builder.setView(txtView);
- //positive button to dismiss the dialog by pressing OK
- builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- });
- //show the builder...
- builder.show();*/
- }
- return super.onOptionsItemSelected(item);
- }
- }
- activity_main.xml
- ==================
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <ListView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/lstFriends"/>
- </LinearLayout>
- CustomMenu.java
- ==================
- package com.example.android.mymenu;
- import android.content.Context;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.Toast;
- /**
- * Created by android on 19/01/2017.
- */
- public class CustomMenu extends AppCompatActivity {
- private int groupId=1;
- int homeId= Menu.FIRST;
- int profileId = Menu.FIRST+1;
- int searchId = Menu.FIRST+2;
- int dealId = Menu.FIRST+3;
- int helpId = Menu.FIRST+4;
- int contactus = Menu.FIRST+5;
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_custom_menu);
- this.context=this;
- }
- /*@Override
- public boolean onCreateOptionsMenu(Menu menu) {
- //adding items to our menu
- menu.add(groupId,homeId,homeId,"Home");
- menu.add(groupId,profileId,profileId,"Profile");
- menu.add(groupId,searchId,searchId,"Search");
- menu.add(groupId,dealId,dealId,"Deal");
- menu.add(groupId,helpId,helpId,"Help");
- menu.add(groupId,contactus,contactus,"Contact Us");
- return super.onCreateOptionsMenu(menu);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId())
- {
- case 1:
- Toast.makeText(context, "Home:"+homeId, Toast.LENGTH_SHORT).show();
- break;
- case 2:
- Toast.makeText(context,"Profile:"+profileId,Toast.LENGTH_SHORT).show();
- break;
- case 3:
- Toast.makeText(context, "Search:"+searchId, Toast.LENGTH_SHORT).show();
- break;
- case 4:
- Toast.makeText(context, "Deal:"+dealId, Toast.LENGTH_SHORT).show();
- break;
- case 5:
- Toast.makeText(context, "Help:"+ helpId, Toast.LENGTH_SHORT).show();
- break;
- case 6:
- Toast.makeText(context, "Contact Us:"+contactus, Toast.LENGTH_SHORT).show();
- break;
- }
- return super.onOptionsItemSelected(item);
- }*/
- }
- activity_custom_menu
- ======================
- <?xml version="1.0" encoding="utf-8"?>
- <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:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".CustomMenu">
- </RelativeLayout>
- menu_main.xml (res --> menu --> menu_main)
- ==============
- <?xml version="1.0" encoding="utf-8"?>
- <menu xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="50sp"
- android:layout_width="50sp">
- <item
- android:id="@+id/itemMain"
- android:title="@string/main"/>
- <item
- android:id="@+id/itemAccess"
- android:title="@string/access"/>
- <item
- android:id="@+id/itemInvite"
- android:title="@string/invited"/>
- <item
- android:id="@+id/itemProf"
- android:title="@string/prof"/>
- <item
- android:id="@+id/itemSitting"
- android:title="@string/sitting"/>
- </menu>
- strings.xml
- ============
- <resources>
- <string name="app_name">MyMenu</string>
- <string name="main">ראשי</string>
- <string name="invited">מוזמנים</string>
- <string name="access">אביזרים</string>
- <string name="prof">בעלי מקצוע</string>
- <string name="sitting">הושבה</string>
- <string name="mainPage">עובר לעמוד הראשי</string>
- <string name="accessPage">עובר לעמוד האביזרים</string>
- <string name="invitePage">עובר לעמוד המוזמנים</string>
- <string name="profPage">עובר לעמוד בעלי המקצוע</string>
- <string name="sitPage">עובר לעמוד ההושבה</string>
- </resources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement