views:

140

answers:

3

Hi,

I have been trying to get "getExtra" to work but without success, I have a listview with 4 choices which launch a webpage within a webView class, when the user selects the option lets say option 3 I want to pass the value of 3 to the webView class so that it will load the correct webpage, at the moment all I get is errors, can somebody help with where I am going wrong.

This is my intent

         if (position == 0)  {
                Intent intent = new Intent(this, official.class);
                startActivity(intent);intent.putExtra(webb = 3);}

This is the getextras code in the official class with the webpages I want to load

Bundle webb = getIntent().getExtras(),

variableGet = webb.getInt(webb);

if (webb == 2)      mWebView.loadUrl("http://bcafc.livewwware.co.uk/viewforum.php?f=7&sid=009c462b00069f307ef6dcd09e747f7c");
  if (webb == 3)   mWebView.loadUrl("http://www.bbc.co.uk");
  mWebView.setWebViewClient(new HelloWebViewClient());

Thanks in Advance

+3  A: 
rreeverb
Thank you, I think my problem is I think in Visual basic language far too much.
JonniBravo
A: 

Once again, you'll probably need to post more code in order to have a helpful answer. At a minimum though, your 1st code block should be rewritten as:

if (position == 0)  {
    Intent intent = new Intent(this, official.class);
    webb = 3;
    intent.putExtra("webb", webb);
    startActivity(intent);
}

And to retrieve, something like:

int webb = getIntent().getIntExtra("webb", -1);

You could probably continue use the bundles as you have, but I'm surprised the 1st code block compiles for you and I think this code would be cleaner to understand. Regardless, you need to set the webb value before you start the activity.

kaliatech
A: 

Give this a try:

Intent intent = new Intent(this, official.class);
intent.putExtra("webb", 3);
startActivity(intent);

Then

Bundle extras = this.getIntent().getExtras();
int webb = extras.getInt("webb");
mac