Problem with menu - doesn't respond at all (but I can click)

Put your problem here if it does not fit any of the other categories.

Problem with menu - doesn't respond at all (but I can click)

Postby svebee » Tue Apr 27, 2010 6:06 pm

I added a menu and it's working - actually I can click on "Menu" on a phone, it pops-up and I can click on something, BUT nothing is happening afterwards :? I think that problem is positioning in the class..but where to put it? Here is first (important) part of the code, included menu...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.svebee.prijevoz;
  2.  
  3.  
  4.  
  5. import java.util.List;
  6.  
  7.  
  8.  
  9. import com.google.android.maps.GeoPoint;
  10.  
  11. import com.google.android.maps.MapActivity;
  12.  
  13. import com.google.android.maps.MapController;
  14.  
  15. import com.google.android.maps.MapView;
  16.  
  17. import com.google.android.maps.Overlay;
  18.  
  19. import com.google.android.maps.OverlayItem;
  20.  
  21.  
  22.  
  23. import android.content.Intent;
  24.  
  25. import android.graphics.drawable.Drawable;
  26.  
  27. import android.os.Bundle;
  28.  
  29. import android.view.Menu;
  30.  
  31. import android.view.MenuInflater;
  32.  
  33. import android.view.MenuItem;
  34.  
  35. import android.view.View;
  36.  
  37. import android.widget.Button;
  38.  
  39. import android.widget.LinearLayout;
  40.  
  41. import android.widget.ZoomControls;
  42.  
  43.  
  44.  
  45. public class Karta extends MapActivity {
  46.  
  47.         @Override
  48.  
  49.         protected boolean isRouteDisplayed() {
  50.  
  51.             return false;
  52.  
  53.         }
  54.  
  55.        
  56.  
  57.         LinearLayout linearLayout;
  58.  
  59.  
  60.  
  61.     MapView mapView;
  62.  
  63.     ZoomControls mZoom;
  64.  
  65.    
  66.  
  67.     List<Overlay> mapOverlays;
  68.  
  69.     Drawable drawable;
  70.  
  71.     KartaOverlay itemizedOverlay;
  72.  
  73.    
  74.  
  75.     MapController mc;
  76.  
  77.     GeoPoint p;
  78.  
  79.  
  80.  
  81.     public boolean onCreateOptionsMenu(Menu menu) {
  82.  
  83.         MenuInflater inflater = getMenuInflater();
  84.  
  85.         inflater.inflate(R.menu.menu, menu);
  86.  
  87.         return true;
  88.  
  89.     }
  90.  
  91.  
  92.  
  93.     public boolean onOptionsItemSelected(MenuItem item) {
  94.  
  95.         switch (item.getItemId()) {
  96.  
  97.             case R.id.icon:                                    
  98.  
  99.                 Button nazad = (Button) findViewById(R.id.nazad);
  100.  
  101.                 nazad.setOnClickListener(new View.OnClickListener() {
  102.  
  103.                    public void onClick(View arg0) {
  104.  
  105.                              Intent i = new Intent(Karta.this, NalazimSe.class);
  106.  
  107.                              startActivity(i);
  108.  
  109.                    }
  110.  
  111.                 });
  112.  
  113.             break;
  114.  
  115.             case R.id.icon2:                                    
  116.  
  117.                 Button prikaziOverlay = (Button) findViewById(R.id.prikaziOverlay);
  118.  
  119.                 prikaziOverlay.setOnClickListener(new View.OnClickListener() {
  120.  
  121.                    public void onClick(View arg0) {
  122.  
  123.                            mapOverlays.add(itemizedOverlay);
  124.  
  125.                    }
  126.  
  127.                 });
  128.  
  129.             break;
  130.  
  131.             case R.id.icon3:
  132.  
  133.                 Button sakrijOverlay = (Button) findViewById(R.id.sakrijOverlay);
  134.  
  135.                 sakrijOverlay.setOnClickListener(new View.OnClickListener() {
  136.  
  137.                    public void onClick(View arg0) {
  138.  
  139.                            mapOverlays.clear();
  140.  
  141.                    }
  142.  
  143.                 });  
  144.  
  145.             break;                  
  146.  
  147.         }
  148.  
  149.         return true;
  150.  
  151.     }
  152.  
  153.  
  154.  
  155.    
  156.  
  157.         /** Called when the activity is first created. */
  158.  
  159.     @SuppressWarnings("deprecation")
  160.  
  161.         @Override
  162.  
  163.     public void onCreate(Bundle savedInstanceState) {
  164.  
  165.         super.onCreate(savedInstanceState);
  166.  
  167.         setContentView(R.layout.karta);
  168.  
  169.  
  170.  
  171.         linearLayout = (LinearLayout) findViewById(R.id.zoomview);
  172.  
  173.         mapView = (MapView) findViewById(R.id.mapview);
  174.  
  175.         mZoom = (ZoomControls) mapView.getZoomControls();
  176.  
  177.         linearLayout.addView(mZoom);
Parsed in 0.043 seconds, using GeSHi 1.0.8.4


...
svebee
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Apr 21, 2010 10:19 pm

Top

Postby svebee » Fri Apr 30, 2010 7:37 pm

Alright..I have this code...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     private static final int test1 = 0;
  2.  
  3.     private static final int test2 = 1;
  4.  
  5.  
  6.  
  7.     /* Creates the menu items */
  8.  
  9.     public boolean onCreateOptionsMenu(Menu menu) {
  10.  
  11.         MenuInflater inflater = getMenuInflater();
  12.  
  13.         inflater.inflate(R.menu.options_menu, menu);
  14.  
  15.         menu.add(0, test1, 0, "Menu1");
  16.  
  17.         menu.add(0, test2, 0, "Menu2");
  18.  
  19.         return true;
  20.  
  21.     }
  22.  
  23.  
  24.  
  25.     /* Handles item selections */
  26.  
  27.     public boolean onOptionsItemSelected(MenuItem item) {
  28.  
  29.         switch (item.getItemId()) {
  30.  
  31.         case test1:
  32.  
  33.              Intent i = new Intent(this, NalazimSe.class);
  34.  
  35.              startActivity(i);
  36.  
  37.             return true;
  38.  
  39.         case test2:
  40.  
  41.              Intent i2 = new Intent(this, NalazimSe.class);
  42.  
  43.              startActivity(i2);
  44.  
  45.             return true;
  46.  
  47.         }
  48.  
  49.         return false;
  50.  
  51.     }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


and this in options_menu.xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <menu xmlns:android="http://schemas.android.com/apk/res/android">
  2.  
  3.     <item android:title="Menu1" android:id="@+id/test1"/>
  4.  
  5.     <item android:title="Menu2" android:id="@+id/test2"/>
  6.  
  7. </menu>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


But I have a problem, I have "doubled" menu - every item is repeated twice so I have FIRST Menu1, FIRST Menu2 who aren't working (responding) at all and then after them i have SECOND Menu1 and SECOND Menu2 which are responding just fine. Where is the problem?

** everything is before
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    
  2.  
  3.         /** Called when the activity is first created. */
  4.  
  5.     @SuppressWarnings("deprecation")
  6.  
  7.         @Override
  8.  
  9.     public void onCreate(Bundle savedInstanceState) {
  10.  
  11.         super.onCreate(savedInstanceState);
  12.  
  13.         setContentView(R.layout.karta);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

...

EDIT: I understand now, I must use or XML or just basic code..so if I use just basic code (
Code: Select all
menu.add(0, test2, 0, "Menu2");
) it works fine but if I use XML (
Code: Select all
inflater.inflate(R.menu.options_menu, menu);
) it doesn't respond..why?

I finally did it..this is full-working code for the menu...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     /* Creates the menu items */
  2.  
  3.     public boolean onCreateOptionsMenu(Menu menu) {
  4.  
  5.         MenuInflater inflater = getMenuInflater();
  6.  
  7.         inflater.inflate(R.menu.menu, menu);
  8.  
  9.         return true;
  10.  
  11.     }
  12.  
  13.  
  14.  
  15.     /* Handles item selections */
  16.  
  17.     public boolean onOptionsItemSelected(MenuItem item) {
  18.  
  19.         switch (item.getItemId()) {
  20.  
  21.         case R.id.test1:
  22.  
  23.              Intent i = new Intent(this, NalazimSe.class);
  24.  
  25.              startActivity(i);
  26.  
  27.             return true;
  28.  
  29.         case R.id.test2:
  30.  
  31.              Intent i2 = new Intent(this, NalazimSe.class);
  32.  
  33.              startActivity(i2);
  34.  
  35.             return true;
  36.  
  37.         }
  38.  
  39.         return false;
  40.  
  41.     }
  42.  
  43.    
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <menu xmlns:android="http://schemas.android.com/apk/res/android">
  2.  
  3.     <item android:title="Menu1" android:id="@+id/test1" android:visible="true" android:enabled="true"/>
  4.  
  5.     <item android:title="Menu2" android:id="@+id/test2" android:visible="true" android:enabled="true"/>
  6.  
  7. </menu>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
svebee
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Apr 21, 2010 10:19 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 14 guests