有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将Int值传递给另一个类

我在一个列表视图中有四个组,每个组有四个url,我想在一个webView中加载。当用户选择要转到的url时,我设置如下值

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

然后,我实现了迁移到webView类的意图,在该类中,我为每个url指定了一个类似这样的值

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

但是如果我在官方文件中声明了值,屏幕将保持空白。课堂上,它起作用了

如何根据用户从listview中所做的选择将该值传递给另一个类。很抱歉,这很难理解


共 (3) 个答案

  1. # 1 楼答案

    就我所知你的问题。。。试着使用额外的工具来传递信息。更多信息请参见here

  2. # 3 楼答案

    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;
        }
    }
    

    希望这有帮助