• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Options Menu

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.... i am new to android and i have been trying to create a menu....but my application stops everytime i run it on the emulator and my phone..i commented out the menu code to check whether my flipper and tab host are working and found that they are working perfectly fine ....plzz help.....Thanks in advance .


this my MainActivity.java

package com.example.screens;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.Toast;
import android.widget.ViewFlipper;

public class MainActivity extends Activity {
TabHost th;

Button b1,b2;
private ViewFlipper ob = null;
Animation in = null , out = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
th=(TabHost) findViewById(R.id.tabhost);
th.setup();

TabHost.TabSpec spec=th.newTabSpec("tag1");
spec.setIndicator("", getResources().getDrawable(R.drawable.text));
spec.setContent(R.id.tab1);
th.addTab(spec);

spec=th.newTabSpec("tag2");
spec.setIndicator("", getResources().getDrawable(R.drawable.imageicon));
spec.setContent(R.id.tab2);
th.addTab(spec);


spec=th.newTabSpec("tag3");
spec.setIndicator("", getResources().getDrawable(R.drawable.videoicon));
spec.setContent(R.id.tab3);
th.addTab(spec);

//end of tab host code

ob = (ViewFlipper) findViewById(R.id.viewFlipper1);
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
in = AnimationUtils.loadAnimation(this,android.R.anim.fade_in);
out = AnimationUtils.loadAnimation(this,android.R.anim.fade_out);
ob.setAnimation(in);
ob.setAnimation(out);
//End of flipper code
} //End of oncreate


public void next(View v)
{
ob.showNext();
}
public void prev(View v)
{
ob.showPrevious();
}





@Override
public boolean onCreateOptionsMenu(Menu menu) {

super.onCreateOptionsMenu(menu);
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.activity_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch(item.getItemId())
{
case R.id.z: Toast.makeText(this,"Moving to hair..",Toast.LENGTH_LONG).show();

return true;
case R.id.o: Toast.makeText(this,"Moving to hair..",Toast.LENGTH_LONG).show();
return true;
case R.id.t: Toast.makeText(this,"Moving to hair..",Toast.LENGTH_LONG).show();
return true;
case R.id.th: Toast.makeText(this,"Moving to hair..",Toast.LENGTH_LONG).show();
return true;
default: return super.onOptionsItemSelected(item);
}//end of switch case

}

}//End of class


AND THIS IS MY menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"; >


<item android:id="@+id/z"
android:title="face" />

<item android:id="@+id/o"
android:title="Hair" />

<item android:id="@+id/t"
android:title="Nails" />

<item android:id="@+id/th"
android:title="Health and Nutrition" />


</menu>
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic