5

मैंने अपने 'आगे' और 'बैक' को काम करने के लिए सबकुछ करने की कोशिश की है।वेबव्यू वापस, ताज़ा करें, आगे बढ़ें? बस काम नहीं करता है!

ताज़ा काम कर रहा है [मैंने इसे 'WebView.reload();' पढ़ने के लिए विधि को बदलकर समझ लिया है। 'webView.refresh(); के बजाय

क्या कोई आगे और पीछे की सहायता कर सकता है? मैंने 'फॉरवर्ड', 'कैनगो फॉरवर्ड' और 'गो फॉरवर्ड' के साथ-साथ 'बैक', 'कैनगोबैक' और 'गोबैक' की कोशिश की है। कोई त्रुटि कोड नहीं है हालांकि उनमें से कोई भी तरीका वास्तव में कुछ भी नहीं करता है।

public boolean onCreateOptionsMenu(Menu menu) { 
    super.onCreateOptionsMenu(menu); // Add menu items, second value is the id, use this in the onCreateOptionsMenu 
    menu.add(0, 1, 0, "Back"); 
    menu.add(0, 2, 0, "Refresh"); 
    menu.add(0, 3, 0, "Forward"); 
    return true; // End of menu configuration 
} 
public boolean onOptionsItemSelected(MenuItem item){ // Called when you tap a menu item 
    switch (item.getItemId()){ 
     case 1: //If the ID equals 1, go back 
      webView.goBack(); 
     return true; 
     case 2 : //If the ID equals 2, refresh 
      webView.reload(); 
     return true; 
     case 3: //If the ID equals 3, go forward 
      webView.goForward(); 
     return true; 
     } 
    return false; 
    } 
@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { // Enables browsing to previous pages with the hardware back button 
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { // Check if the key event was the BACK key and if there's history 
     webView.goBack(); 
     return true; 
    } // If it wasn't the BACK key or there's no web page history, bubble up to the default 
     // system behavior (probably exit the activity) 
    return super.onKeyDown(keyCode, event); 
} 

}

उत्तर

4

कोड आप भाग जहां वेबव्यू बनाने और यूआरएल के बीच नेविगेट कर रहे हैं शामिल नहीं है साझा की है। तो मैं बस अनुमान लगा रहा हूं कि क्या हो रहा है।

ऐसा लगता है कि webview आपकी कक्षा का एक उदाहरण क्षेत्र है जिसका हिस्सा आपने प्रश्न में दिखाया है। क्या यह हो सकता है कि हर बार जब आप किसी नए पृष्ठ पर नेविगेट करते हैं तो webView पुनर्निर्मित किया जा रहा है? यही कारण है कि कोड की तरह कुछ है, यह है:

webview = new WebView(this); 
webview.loadUrl("http://slashdot.org/"); 

तो यह है कि क्या किया जा रहा है, आप सभी की जरूरत बनाने के लिए है 'WebView' एक बार और सिर्फ loadUrl हर आप नए url पर नेविगेट करने की जरूरत है कहते हैं। इस तरह वेबव्यू इंस्टेंस इतिहास को बनाए रखने में सक्षम होगा।

+0

धन्यवाद, मैंने बस लोड यूआरएल की सिफारिश की है और यह बहुत अच्छा काम करता है! आप शानदार हैं! –

+0

यह जानकर अच्छा लगा कि अंधा अनुमान काम करता है :) –

संबंधित मुद्दे