JonniBravo
JonniBravo

Reputation: 1071

Passing a Int value to another class

I have four groups in a listview each with four url's I want to load in a webView. When the user select a url to goto I set a value like so;

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

I then carryout the intent to move to the webView class where I have given each url a value like so;

if (webb == 2) mWebView.loadUrl("http://yahoo.com");
if (webb == 3) mWebView.loadUrl("http://www.bbc.co.uk");

But the screen stays blank, if I state the value inside the official.class it works.

How can I get this value to pass to another class based on the selection the user makes from the listview. Sorry if this is hard to understand.

Upvotes: 0

Views: 1024

Answers (3)

kaliatech
kaliatech

Reputation: 17877

If your question is how to share data between activities (such as your webb value), then you might want to look at the Intent.putExtra(...) methods. More info:

Upvotes: 1

JonniBravo
JonniBravo

Reputation: 1071

package com.ff.org.l2forums;
import com.ff.org.official;
import com.ff.org.league2.RssActivityc;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Forums extends ListActivity {
public int webb = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // Create an array of Strings, that will be put to our ListActivity
        String[] names = new String[] { "Official Forum", "Claret & Banter", "Bantams Fan Blog", "Official Website", "League Two Football Forum", "Boy From Brazil Blog", "Supporters Trust"};
        // Create an ArrayAdapter, that will actually make the Strings above
        // appear in the ListView
        this.setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_checked, names));
    }


        // Get the item that was clicked
        @Override
        public void onListItemClick(ListView l, View v, int position, long id) {

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

            if (position == 9) {

                String url = "http://bcafc.livewwware.co.uk/index.php";
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i);
        }

                            if (position == 1) {

            String url = "http://www.claretandbanter.com/forum.php";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);




public class official extends Activity {

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
        WebView mWebView;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.browser1);

            mWebView = (WebView) findViewById(R.id.webview);
            mWebView.getSettings().setJavaScriptEnabled(true);

    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());



        }
}
class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

Hope this helps

Upvotes: 0

Asahi
Asahi

Reputation: 13506

As far as I understand your question... Try using extras to pass info along with the intent. More info can be found here

Upvotes: 0

Related Questions