For the compiler error:

Replace
  startActivity(new Intent(this, BroadcastActivity.class));
with
  startActivity(new Intent(MainMenuActivity.this,
BroadcastActivity.class));

The call to startActivity is within the (anonymous) inner-class 'new
View.OnClickListener()' and 'this' points to the OnClickListener's
instance. Since OnClickListener is not a Context (i.e. it does not
implement Context), you get the compiler error. You don't want this
inner-class to implement Context. Instead, you want to refer back to
the inner-class' outer-class, which is MainMenuActivity. You can tell
the compiler to do so, by appending 'MainMenuActivity.' to 'this'.

You may want to read up on Java (non-static) inner-classes.

Welcome to Android programming :-)


On Jan 21, 4:29 pm, LenseOnLife <[email protected]> wrote:
> Hi,
>
> Please bear with me, I am a newbie geriatric who started programming
> when computers had discrete transistors and am only now returning
> after about a decade of forced retirement.  Spent the last year
> using .NET and now trying to come to grips with Android/Java.
> Evidently, I still need to purchase some more books, but in the
> mantime, someone out there might be able to put me back onto the
> straight and narrow.
>
> OVERVIEW:  In the manifest I start with 'inthebeginning' activity.
> This does nothing more than start another activity called
> MainMenuActivity which in turn has three buttons, each of which calls
> their own activity.  InTheBeginningActivity works fine and amazed me
> that I actually got something working so easily.
>
> InTheBeginningActivity
>
> package com.cit.BroadcastSim;
>
> import android.app.Activity;
> import android.content.Intent;
> import android.os.Bundle;
>
> public class InTheBeginningActivity extends Activity {
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.splash);        // Inflate the
> inthebeginning.xml file
>
>         startActivity(new Intent(this, MainMenuActivity.class));
>         // Since we wont be coming back to this activity ever again
>         InTheBeginningActivity.this.finish();
>     }
>
> }
>
> Now for the troublesome one.  Although there are three buttons, I have
> only tried coding one adn have come a cropper.
>
> package com.cit.BroadcastSim;
>
> import android.app.Activity;
> import android.content.Intent;
> import android.os.Bundle;
> import android.widget.Button;
> import android.view.*;
>
> public class MainMenuActivity extends Activity {
>     // Launched by InTheBeginningActivity.
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.mainmenu);  // Inflate the
> mainmenu.xml file
>
>         // Set up listeners for the three menu buttons
>         //      Broadcast, Setup and Exit
>         // Firstly we have to find the buttons.
>         // We do this by using their IDs and findViewById()
>
>         Button btnBroadcast = (Button)
> this.findViewById(R.id.btnBroadcast);
>         btnBroadcast.setOnClickListener(new View.OnClickListener(){
>                 public void onClick(View v){
>                         // Start Activity Class Broadcast
>                 startActivity(new Intent(this,
> BroadcastActivity.class));
>                 // Since we wont be coming back to this activity ever
> again
>                 MainMenuActivity.this.finish();
>                 }
>         });
>     }
>
> }
>
> The line with startActivity has a lightbulb with a red x :-( and teh
> error message when I hover over it is:
> The constructor Intent(new View.OnClickListener(){},Class
> <BroadcastActivity>) is undefined
>
> Everything within brackets is underlined in red and when I hover it I
> get the same as above with a hyperlinked hint
> remove arguments to match Intent()
> which works, the error goes, but then I am left with
> startActivity(new Intent());
> which doesn't do very much!
>
> Have scratched my head till all the hair has fallen out, so can
> someone out there in programming land tell me (gently) what I am doing
> wrong.
>
> Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to