2010-10-14 91 views
0

我有一個listview中有四個組,每個都有四個我想在webView中加載的url。當用戶選擇一個網址轉到我設置一個值如此;傳遞一個Int值到另一個類

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

但是屏幕保持空白,如果我聲明它在官方類中的值,它的工作原理。

如何根據用戶對列表視圖的選擇將該值傳遞給另一個類。對不起,如果這很難理解。

+0

您要查看的活動開始startActivity(意向);知道webb的價值?那是對的嗎? – stew 2010-10-14 20:07:07

+0

您尚未提供足夠的信息。你將需要發佈更多的代碼......可能是整個兩個類,因爲它聽起來像一個簡單的編碼錯誤,你混淆了變量作用域。 (並且你應該使用代碼格式化按鈕來使得它更容易閱讀) – kaliatech 2010-10-14 20:11:25

+1

你知道你的塊沒有與你的if相關聯,因爲webb = webb +2;是執行的命令,如果if 「是真的,對嗎? – 2010-10-14 20:14:09

回答

0

據我瞭解你的問題...嘗試使用額外的傳遞信息與意圖一起。更多信息可以發現here

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

希望這有助於

相關問題