1. Download our Official Android App: Forums for Android!

Apps Hide menu group by java?

Discussion in 'Android Development' started by AmrAbdeen, Jul 30, 2016.

  1. AmrAbdeen

    AmrAbdeen Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jul 30, 2016

    Jul 30, 2016
    2
    0
    5
    Male
    Hi,
    i beginner into android & Java :)


    ACTIVITY.xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <menu xmlns:android="http://schemas.android.com/apk/res/android">
    3.  
    4.     <group  android:checkableBehavior="single"
    5.             android:id="@+id/EGYPT"
    6.             android:visible="true">
    7.  
    8.         <item
    9.             android:id="@+id/x1"
    10.             android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
    11.             android:title="v1"/>
    12.         <item
    13.             android:id="@+id/x2"
    14.             android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
    15.             android:title="v2"/>
    16.         <item
    17.             android:id="@+id/x3"
    18.             android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
    19.             android:title="v3"/>
    20.  
    21.     </group>
    22.  
    23.     <item android:title="Communicate">
    24.         <menu>
    25.             <item
    26.                 android:id="@+id/nav_share"
    27.                 android:icon="@drawable/ic_menu_share"
    28.                 android:title="Share" />
    29.             <item
    30.                 android:id="@+id/nav_send"
    31.                 android:icon="@drawable/ic_menu_send"
    32.                 android:title="Send" />
    33.         </menu>
    34.     </item>
    35.  
    36. </menu>
    37.  


    ACTIVITY.java
    Code (Text):
    1. package com.example.amr.myapplication;
    2.  
    3. import android.content.Context;
    4. import android.os.Bundle;
    5. import android.support.design.widget.NavigationView;
    6. import android.support.v4.view.GravityCompat;
    7. import android.support.v4.widget.DrawerLayout;
    8. import android.support.v7.app.ActionBarDrawerToggle;
    9. import android.support.v7.app.AppCompatActivity;
    10. import android.support.v7.widget.Toolbar;
    11. import android.telephony.TelephonyManager;
    12. import android.view.Menu;
    13. import android.view.MenuItem;
    14. import android.view.View;
    15. import android.webkit.WebView;
    16. import android.webkit.WebViewClient;
    17. import android.widget.TextView;
    18.  
    19. import java.util.Locale;
    20.  
    21. public class MainActivity1 extends AppCompatActivity
    22.         implements NavigationView.OnNavigationItemSelectedListener {
    23.  
    24.     WebView browser;
    25.  
    26.     @Override
    27.     protected void onCreate(Bundle savedInstanceState) {
    28.         super.onCreate(savedInstanceState);
    29.         setContentView(R.layout.activity_main1);
    30.         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    31.         setSupportActionBar(toolbar);
    32.  
    33.  
    34.         DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    35.         ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
    36.                 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    37.         drawer.setDrawerListener(toggle);
    38.         toggle.syncState();
    39.  
    40.         NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    41.         navigationView.setNavigationItemSelectedListener(this);
    42.  
    43. // MyCode
    44.         browser = (WebView) findViewById(R.id.webView);
    45.         browser.setWebViewClient(new MyBrowser());
    46.         browser.getSettings().setLoadsImagesAutomatically(true);
    47.         browser.getSettings().setJavaScriptEnabled(true);
    48.         browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    49.         browser.loadUrl("http://www.youm7.com/");
    50. //
    51.  
    52.     }
    53.  
    54.     @Override
    55.     public boolean onPrepareOptionsMenu(Menu menu){
    56.         super.onPrepareOptionsMenu(menu);
    57.         menu.clear();
    58.  
    59.         menu.setGroupVisible(R.id.EGYPT,false);
    60.  
    61.         return true;
    62.     }
    63.  
    64.     @Override
    65.     public void onBackPressed() {
    66.         DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    67.         if (drawer.isDrawerOpen(GravityCompat.START)) {
    68.             drawer.closeDrawer(GravityCompat.START);
    69.         } else {
    70.             super.onBackPressed();
    71.         }
    72.     }
    73.  
    74.     @Override
    75.     public boolean onCreateOptionsMenu(Menu menu) {
    76.         // Inflate the menu; this adds items to the action bar if it is present.
    77.         getMenuInflater().inflate(R.menu.main_activity1, menu);
    78.  
    79.         return true;
    80.     }
    81.  
    82.     @Override
    83.     public boolean onOptionsItemSelected(MenuItem item) {
    84.         // Handle action bar item clicks here. The action bar will
    85.         // automatically handle clicks on the Home/Up button, so long
    86.         // as you specify a parent activity in AndroidManifest.xml.
    87.         int id = item.getItemId();
    88.  
    89.  
    90.         return super.onOptionsItemSelected(item);
    91.     }
    92.  
    93.  
    94.  
    95.     @Override
    96.     public boolean onNavigationItemSelected(MenuItem item) {
    97.         // Handle navigation view item clicks here.
    98.  
    99.         int grp_id = item.getGroupId();
    100.  
    101.  
    102.         DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    103.         drawer.closeDrawer(GravityCompat.START);
    104.         return true;
    105.     }
    106.  
    107.  
    108.      private class MyBrowser extends WebViewClient{
    109.          //@Override
    110.          public boolean shoudOverrideUrlLoading(WebView view, String url){
    111.              view.loadUrl(url);
    112.              return true;
    113.          }
    114.      }
    115.  
    116.  
    117.  
    118. }
    119.  
    :: My problem is ..
    I want check Group id when start up activity .. IF group id = EGYPT then Hidden or Invisible Group .
    I tried more than once but i can't do that ..


    Please help me..
    Thanks ..
     

    Advertisement

  2. AmrAbdeen

    AmrAbdeen Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jul 30, 2016

    Jul 30, 2016
    2
    0
    5
    Male
  3. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #8
    Points:
    2,138
    Posts:
    22,293
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,293
    23,645
    2,138
    Male
    space alien ;)
    Indy
    Welcome to AF, @AmrAbdeen--I've moved your thread over here to our Application Development area where your thread is probably more at home :).

    Cheers and best of luck!
     

Share This Page

Loading...