Intent/Activity problem

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

Intent/Activity problem

Postby ali90 » Thu Mar 17, 2011 11:45 am

hi i am trying to create an application where there are multiple screens. i am fairly new at this, when i run the emulator it just force closes. i am confused... i think the syntax or something of my code is incorrect. i want to be able to click a button to open a new class. can someone help me please?
ali90
Freshman
Freshman
 
Posts: 4
Joined: Sun Nov 21, 2010 5:59 pm

Top

Re: Intent/Activity problem

Postby ali90 » Thu Mar 17, 2011 11:47 am

my code:
Code: Select all
[syntax="xml"]
public class mainmenu extends Activity{
   
   private static final int ACTIVITY_MM =0;
   private static final int ACTIVITY_LIST=1;
   private static final int ACTIVITY_CREATE =2;

   private Button btn_mmadd;
   private Button btn_mmview;
   
     @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main_menu);
          
           btn_mmadd = (Button) findViewById(R.id.btn_mmadd);
           btn_mmview = (Button) findViewById(R.id.btn_mmview);
          
           registerButtonListeners();
      
       }
     private void createRecipe(){
          Intent i = new Intent(this, recipe_create.class);
          startActivityForResult(i, ACTIVITY_CREATE);
       }
     private void viewRecipe(){
         Intent i = new Intent(this, recipe_list.class);
           startActivityForResult(i, ACTIVITY_LIST);
       }
     private void registerButtonListeners() {
         
         btn_mmadd.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                 //createRecipe();
                 setResult(RESULT_OK);
                  Toast.makeText(mainmenu.this, getString(R.string.mmadd), Toast.LENGTH_SHORT).show();
                  finish();
              }
            
           });
         btn_mmview.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                 setResult(RESULT_OK);
                  Toast.makeText(mainmenu.this, getString(R.string.mmview), Toast.LENGTH_SHORT).show();
                  finish();
              }         
           });      
      }
     @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent intent)
      {
         super.onActivityResult(requestCode, resultCode, intent);
   
      }
}
[/syntax]
ali90
Freshman
Freshman
 
Posts: 4
Joined: Sun Nov 21, 2010 5:59 pm

Re: Intent/Activity problem

Postby raj_J2ME » Thu Mar 17, 2011 11:55 am

It will be better to look at the main_menu XML in the layout format, how this looks like?
What error the emulator/logcat is gonna display if any?
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Intent/Activity problem

Postby ali90 » Fri Mar 18, 2011 3:06 pm

i am literally a beginner at this... but did you want to see the code for the xml file?

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <AbsoluteLayout
  3. android:id="@+id/mm_layout"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. xmlns:android="http://schemas.android.com/apk/res/android"
  7. android:background="@drawable/mainscreen">
  8. >
  9. <Button
  10. android:id="@+id/btn_mmadd"
  11. android:layout_width="143px"
  12. android:layout_height="54px"
  13. android:text="Add A New Recipe"
  14. android:layout_x="87px"
  15. android:layout_y="256px"
  16. >
  17. </Button>
  18. <Button
  19. android:id="@+id/btn_mmview"
  20. android:layout_width="143px"
  21. android:layout_height="54px"
  22. android:text="View Recipes"
  23. android:layout_x="87px"
  24. android:layout_y="318px"
  25. >
  26. </Button>
  27. </AbsoluteLayout>
  28.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
ali90
Freshman
Freshman
 
Posts: 4
Joined: Sun Nov 21, 2010 5:59 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 9 guests