menu interview questions
Top menu frequently asked interview questions
I'm building an Android app and I want to copy the text value of an EditText widget. It's possible for the user to press Menu+A
then Menu+C
to copy the value, but how would I do this programmatically?
Source: (StackOverflow)
I am completely new to Qt.
I started with a new Qt4 GUI Application.
Using the designer, I have created a menu like so:
File
- Exit
How do I get an action associated with the menu item?
I found something called the 'Signals and slots editor' but have no idea how to use it.
Source: (StackOverflow)
I'm currently struggling with this issue. I need to check if the device, where the app is installed, has a hardware menu key. Because it is not existing on some devices like Galaxy Nexus, I'm showing it directly in the UI in this case.
I have already looked at PackageManager.hasSystemFeature(), but didn't find anything useful there.
Has anyone already done this?
Source: (StackOverflow)
My users can change the Locale within the app (they may want to keep their phone settings in English but read the content of my app in French, Dutch or any other language ...)
Why is this working perfectly fine in 1.5/1.6 but NOT in 2.0 anymore ???
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case 201:
Locale locale2 = new Locale("fr");
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(
config2, getBaseContext().getResources().getDisplayMetrics());
// loading data ...
refresh();
// refresh the tabs and their content
refresh_Tab ();
break;
case 201: etc...
The problem is that the MENU "shrinks" more and more everytime the user is going through the lines of code above ...
This is the Menu that gets shrunk:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 100, 1, "REFRESH").setIcon(android.R.drawable.ic_menu_compass);
SubMenu langMenu = menu.addSubMenu(0, 200, 2, "NL-FR").setIcon(android.R.drawable.ic_menu_rotate);
langMenu.add(1, 201, 0, "Nederlands");
langMenu.add(1, 202, 0, "Français");
menu.add(0, 250, 4, R.string.OptionMenu2).setIcon(android.R.drawable.ic_menu_send);
menu.add(0, 300, 5, R.string.OptionMenu3).setIcon(android.R.drawable.ic_menu_preferences);
menu.add(0, 350, 3, R.string.OptionMenu4).setIcon(android.R.drawable.ic_menu_more);
menu.add(0, 400, 6, "Exit").setIcon(android.R.drawable.ic_menu_delete);
return super.onCreateOptionsMenu(menu);
}
What should I do in API Level 5 to make this work again ?
HERE IS THE FULL CODE IF YOU WANT TO TEST THIS :
import java.util.Locale;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.widget.Toast;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
SubMenu langMenu = menu.addSubMenu(0, 200, 2, "NL-FR").setIcon(android.R.drawable.ic_menu_rotate);
langMenu.add(1, 201, 0, "Nederlands");
langMenu.add(1, 202, 0, "Français");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case 201:
Locale locale = new Locale("nl");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
Toast.makeText(this, "Locale in Nederlands !", Toast.LENGTH_LONG).show();
break;
case 202:
Locale locale2 = new Locale("fr");
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
Toast.makeText(this, "Locale en Français !", Toast.LENGTH_LONG).show();
break;
}
return super.onOptionsItemSelected(item);
}
}
AND HERE IS THE MANIFEST :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cousinHub.ChangeLocale"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
THIS IS WHAT I FOUND :
<uses-sdk android:minSdkVersion="5" />
=> IT WORKS JUST FINE ...
<uses-sdk android:minSdkVersion="3" />
=> Menu shrinks every time you change the locale !!!
as I want to keep my application accessible for users on 1.5, what should I do ??
Source: (StackOverflow)
I'm trying to change the title of a menu item from outside of the onOptionsItemSelected(MenuItem item) method.
I already do the following;
public boolean onOptionsItemSelected(MenuItem item){
try{
switch(item.getItemId()){
case R.id.bedSwitch:
if(item.getTitle().equals("Set to 'In bed'")){
item.setTitle("Set to 'Out of bed'");
inBed = false;
}else{
item.setTitle("Set to 'In bed'");
inBed = true;
}
break;
}
} catch(Exception e){
Log.i("Sleep Recorder", e.toString());
}
return true;
}
however i'd like to be able to modify the title of a particular menu item outside of this method
Thanks in advance for your help
Andy
Source: (StackOverflow)
How can I disable the "Save Video As..." from the right-click menu to prevent from clients from downloading the video?
And, are there is more complete solutions that prevent the client from accessing the file path directly?
Thanks
Source: (StackOverflow)
I would like to open the optionsMenu programmatically without a click on the menu key from the user. How would I do that?
Source: (StackOverflow)
In XAML, how do I put a standard dividing line in a menu?
eg
<MenuItem Header="_File" Name="m_fileMenu">
<MenuItem Header="_Open" Command="ApplicationCommands.Open"/>
<!-- Trying to put a divider here! -->
<MenuItem Header="-" /> <!-- Wrong guess -->
<MenuItem Header="E_xit" Command="ApplicationCommands.Close" />
</MenuItem>
Source: (StackOverflow)
<Menu Height="22" Margin="0,109,102,0" Name="menu1" VerticalAlignment="Top">
<MenuItem Header="Reports">
<MenuItem.Icon>
<Image Width="20" Height="20" Source="/XSoftArt.WPFengine;component/Images/export32x32xp.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Export" />
<MenuItem Header="New record" />
</Menu>
How to define MenuItem.Icon so that the MenuItemHeader text would be placed below the menu item image?Thanks for help!
Source: (StackOverflow)
I want to add a submenu inside my OptionsMenu to a menuItem, programatically according to my parameters. I've checked "MenuItem" in android sdk and there is no addSubMenu() method!, although you can find "hasSubMenu()" and "getSubMenu".
Was thinking on doing this in onCreateOptionsMenu:
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem mi = menu.getItem(MYITEMID); // << this is defined in my XML optionsMenu
SubMenu subm = mi.addSubMenu(0,1,0,"Map 1"); // no addSubMenu() method!!!???
....
How do I create a submenu inside a menuitem in code?
Source: (StackOverflow)
I'm currently creating a right-click context menu by instantiating a new JMenu
on right click and setting its location to that of the mouse's position... Is there a better way?
Source: (StackOverflow)
W3Schools.com and I'm pretty sure I remember seeing W3C.org state that <menu>
should be used for Toolbar menus and listing form control commands.
So, which one should I use for my main menu? Nav
, or Menu
? Does it matter?
Source: (StackOverflow)
Since I implented app compat my searchview doesn't work anymore:
Process: com.laurenswuyts.witpa, PID: 26666
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setSearchableInfo(android.app.SearchableInfo)' on a null object reference
at com.laurenswuyts.witpa.Activities.Events.EventActivity.onCreateOptionsMenu(EventActivity.java:75)
at android.app.Activity.onCreatePanelMenu(Activity.java:2820)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:275)
at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:276)
at android.support.v7.app.ActionBarActivityDelegate$1.onCreatePanelMenu(ActionBarActivityDelegate.java:79)
at android.support.v7.widget.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:49)
at android.support.v7.internal.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:459)
at android.support.v7.internal.app.ToolbarActionBar$1.run(ToolbarActionBar.java:69)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
So nullpointer for searchview while I have it:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.event_main, menu);
// Get the SearchView and set the searchable configuration
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
return super.onCreateOptionsMenu(menu);
}
And in my menu I have this:
<!-- Search Widget -->
<item android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/ic_action_search"
app:showAsAction="always"
android:actionViewClass="android.support.v7.widget.SearchView"/>
I have no idea why it doesn't work anymore but it happened since I started using app compat 21.
Regards,
Source: (StackOverflow)
First, let me say that I abominate this feature in Windows Vista and Windows 7. Second, I want to do it. Here is a question asking how to do what I want here, in WPF.
I want to do the same thing, but in Delphi, using VCL stock components, TMainMenu or Action Manager menus, or some available third party components, even Toolbar2000 or some other library.
Feature of Windows Vista/Windows 7 explorer main-menus:
- it's not visible when the app starts
- pressing and releasing Alt makes it visible
- pressing and releasing Alt again makes it invisible again
- repeatable.
- hotkeys work on menu items, even when menu is invisible*
(* Windows Explorer Hotkeys Example: Ctrl+A in Microsoft Windows Explorer selects all even when the menus are invisible, Alt+T = bring up Tools popup menu, even when the whole menu is hidden).
Update: Demo using accepted answer can be downloaded here. (HiddenMenu.zip)
Source: (StackOverflow)
I would like custom background & text color for my overflow menu. It works fine with devices without hardware menu button, but I'm not able to style devices with hardware menu button. See the screenshots:
I'm using these styles:
<style name="Theme.settleup" parent="@style/Theme.Sherlock.Light.DarkActionBar">
<item name="android:popupMenuStyle">@style/settleup_PopupMenu</item>
<item name="android:actionMenuTextColor">@android:color/white</item>
</style>
<style name="settleup_PopupMenu" parent="@style/Widget.Sherlock.ListPopupWindow">
<item name="android:popupBackground">@drawable/menu_dropdown_panel_settleup</item>
</style>
Source: (StackOverflow)