menu android not switching activities - android

Well this is my code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.news:
Intent j = new Intent(MainScreen.this,LatestNewsScreen.class);
startActivity(j);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
this is my manifest lines I added:
<activity android:name=".LatestNewsScreen"
> </activity>
and i the latestNewsScreen I must see an simple textView. I press menu and if I click nothing happens. Why Is that?
this is my menu.xml code:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/news"
android:icon="#drawable/icon"
android:title="About us" />
</menu>
Any help?

When you click menu, you should see the menu items (in this case just the one) appear at the bottom of the screen. When you click that item then your other activity should start.
Maybe your icon is not the right size, try changing it to the system one, like
android:icon="#android:drawable/ic_menu_info_details"
and see what happens

Related

How to hide action Overflow menu (Not menu item) from activity and keep in Fragment? [Not solved]

I have a requirement that action Overflow menu icon should show in fragment, but not activity.
Code:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.filter:
openFilterDialog();
return true;
default:
break;
}
return false;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_mail_list, menu);
return true;
}
menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.dwisehealthcare.pmstablet.consult.activity.ConsultActivity">
<item
android:id="#+id/filter"
android:title="Filter"
android:icon="#drawable/ic_baseline_filter_list_24"
app:showAsAction="always" />
</menu>
I searched, but everyone is talking about menu item, not action icon.
Try this link may be it will help you, with the help of this you can add menu anywhere you want.Just add an ImageView to that fragment and when you click that imageView you create a PopUpMenu

Android - Cannot see Options Menu when extends SherlockFragmentActivty

![Layout Look like this][1]
[1]strong text: http://i.stack.imgur.com/CIsz8.png
I am trying to create a menu, but I am unable to see the menu.i am able to see menu in fragments properly. but cannot see in the sherlockfragmentactivity that is my main frame for fragment.
when i click on menu they doesn't take any action.
menu code
<group android:id="#+id/dashbardmenu">
<item
android:id="#+id/abc"
android:title="ABC">
</item>
<item
android:id="#+id/setting"
android:title="Setting">
</item>
</group>
<group android:id="#+id/fragmentmenu" >
<item
android:id="#+id/form"
android:icon="#drawable/ic_send"
android:showAsAction="ifRoom"
android:title="Form">
</item>
<item
android:id="#+id/resetform"
android:title="Reset Form">
</item>
</group>
im using visibility & invisibility for particular file.
java code
1st way
public boolean onCreateOptionaMenu(Menu menu ){
MenuInflater inflater = this.getSupportMenuInflater();
inflater.inflate(R.menu.activity, menu);
menu.setGroupVisible(R.id.fragmentmenu, false);
return super.onCreateOptionsMenu(menu);
}
2nd way
public boolean onCreateOptionaMenu(Menu menu,MenuInflater inflater ){
inflater.inflate(R.menu.activity, menu);
menu.setGroupVisible(R.id.fragmentmenu, false);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
super.onOptionsItemSelected((MenuItem)item);
switch (item.getItemId()){
case R.id.abc:
//Some action
case R.id.setting:
//Some action
default:
return false;
}
}
public boolean onOptionsItemSelected(MenuItem item){
super.onOptionsItemSelected((MenuItem)item);
switch (item.getItemId()){
case R.id.abc:
//Some action
case R.id.setting:
//Some action
default:
return true;
}
}
Where is my Mistake Anyone help me???
Did you call this?
setHasOptionsMenu(true);
Also you have a typo - method name is onCreateOptionsMenu but you have twice onCreateOptionaMenu

Action items not selectable Android Sherlock Actionbar

I'm implementing action bar with items. I can't see the selected item effect (background selection color) when I click on an item in the actions :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/menu_item_share_action_provider_action_bar"
android:showAsAction="always"
android:title="TTTTTTT"
android:checkable="true"
/>
<item android:id="#+id/menu_item_share_action_provider_action_bar"
android:showAsAction="always"
android:title="AAAAAA"
android:checkable="true"
/>
</menu>
On My SherlockActivity :
#Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
UPDATE:
You need to do something like this (switching the icons ids):
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
Intent intent = new Intent(this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
-----------
Have you done something like this:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
This is needed to inflate the XML file.
Maybe setting identical id's on both items is causing the problem. Did you try to change one of them?

Android Hardware Menu button isn't working for me

I'm using this code to display a menu, but it isn't doing anything when I press the menu button.
This is in a view flipper, I don't know if that has anything to do with the problem.
I used this before and with no problems at all:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.new_game:
return true;
case R.id.help:
finish();
return true;
}
return false;
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/new_game"
android:title="new_game" />
<item android:id="#+id/help"
android:title="clear" />
</menu>
You are not calling the superclass methods.
Dont you have to have some icon attached to it?
android:icon="#drawable/ic_menu_add"
for example

Android menu will not appear when the menu button is pressed in AVD

I have defined a menu as laid out by http://developer.android.com/guide/topics/ui/menus.html
Here is my menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_home"
android:icon="#drawable/ic_menu_home"
android:title="Main Menu" />
<item android:id="#+id/menu_signout"
android:icon="#drawable/ic_menu_signout"
android:title="Sign Out" />
</menu>
and my code, placed in my activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menu_home:
startActivity(new Intent(ManageUsersActivity.this, MainMenuActivity.class));
finish();
return true;
case R.id.menu_signout:
//TODO: issue signout to clear the cookie
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Unfortunately, when I click the menu button, nothing happens.
Try chaining to the superclass in onCreateOptionsMenu(). Here is a sample project demonstrating the use of MenuInflater for options and context menus.

Categories

Resources