Probels With Menu

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Probels With Menu

Postby ShanuSaxena » Tue Jan 27, 2009 1:31 pm

Hi all,
I am working on game menu (android.view.Menu;), actual start game menu is done using .png+drawbitmap+drawrect etc etc....but for end game, restart game n other settings m using android.view.Menu;
wen activity starts n main game menu gets displayed which is on view.....if click menu button 1st widout pressing ne other key den menu pops up ...but if ne other key was pressed b4 menu button den menu does not pops-up.....

if i call it explicitly in onKeyDown() then menu pops-up and when release menu button then it goes down.

can ne1 guess wat might be da prob?? javascriptemoticon(':?:')
thanx in advance..........


package com.sv;

import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;

/**
* Implements the main application class.
*/
public class ASDF extends Activity implements Commands {
private static MainWindow mWindow;
public static final int Quit_id = Menu.FIRST;
private static int temp1;
static boolean first = false;

static Intent i;

@Override
public synchronized void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setRequestedOrientation(0); // for landscape mode

mWindow = new MainWindow(this, this); //view where game starts

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

requestWindowFeature(Window.FEATURE_NO_TITLE);


setContentView(mWindow);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
Log.d("onCreateOptionsMenu", "onCreateOptionsMenu");

menu.add(0, Quit_id, 0, null).setShortcut('0', 'r').setIcon(
android.R.drawable.ic_menu_close_clear_cancel);
Log.d("onCreateOptionsMenu11", "onCreateOptionsMenu1111111");
return true;

// return super.onCreateOptionsMenu(menu);
}

//
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case Quit_id:
quit();
}
return super.onOptionsItemSelected(item);
}

public void openMenu() { //for calling menu explicitly same as openOptionMenu();
this.getWindow().openPanel(Window.FEATURE_OPTIONS_PANEL,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU));
}

} :?:
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Top

Postby ErnestoGuevara » Tue Jan 27, 2009 11:41 pm

I do not understand you.

Che
ErnestoGuevara
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Thu Jan 08, 2009 2:02 am

Postby ShanuSaxena » Wed Jan 28, 2009 6:42 am

hey thanx that u look into the code.....
plz tell me which part of the code or prob u did not understand....
in short prob is that menu wont show on my view n if i call it by openOptionMenu() on menu click event then it pops up but as soon as i release the menu button it gets minimized....
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Postby hebbalhrk » Wed Jan 28, 2009 10:37 am

In the onCreateOptionsMenu:
public boolean onCreateOptionsMenu(final Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, Quit_id, Quit_id, Quit_id).setShortcut('0', 'r').setIcon(
android.R.drawable.ic_menu_close_clear_cancel);

return true;
}

Prepare your Options menu
public final boolean onPrepareOptionsMenu(final Menu menu) {
final boolean isItemSelected = getSelectedItemPosition() >= 0;
menu.findItem(Quit_id).setEnabled(isItemSelected);

return super.onPrepareOptionsMenu(menu);
}

On menu selected:
public boolean onMenuItemSelected(final int featureId, final MenuItem item) {
switch (item.getItemId()) {
case Quit_id:
//Do something.....
return true;

default:
break;
}

return super.onMenuItemSelected(featureId, item);
}
hebbalhrk
Developer
Developer
 
Posts: 37
Joined: Wed Jun 18, 2008 10:35 am

Postby ShanuSaxena » Thu Jan 29, 2009 5:47 am

hello thanx for reply,
I use this code in my game menu and its working fine, but comes one problem when we move center button left and right, after this menu button press then menu pops up but as soon as i release the menu button it gets minimized....
I use this code for call menu:

public void openMenu() {
this.getWindow().openPanel(Window.FEATURE_OPTIONS_PANEL,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU));

}
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Postby ShanuSaxena » Fri Jan 30, 2009 6:54 am

hey i found the cause of this prob......i hv a single view in my game...in setcontentview i hv set view as mainwindow(see above code).....if i remove the onkeydown and onkey up from my code menu works fine.....
does anybody have code dat has both menu n keydown working properly...???
Change is the law of success. Always Smile :)
ShanuSaxena
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Jan 06, 2009 8:28 am
Location: mumbai, india

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests