2011-09-22 77 views
0

我想提醒人們,如果一個頁面沒有加載,並且吐司功能不能保持足夠長的時間(但我留下的代碼和評論如果我想回去的話)。所以我現在試圖做一個自定義對話框,但不會彈出。自定義對話框來提醒網頁沒有加載

我基本上打開網頁,其中工程 我在狀態欄中加入了裝載機所以人們會看到頁面加載,而工作 我添加代碼,以保持導航的應用程序,所以人不出口到一個新的瀏覽器,而工作 正如我所說的,麪包技術上的工作,但不熬夜,只要我想 然後我添加的自定義警告對話框,而這也正是我失敗

我還爲自定義提醒創建了一個單獨的XML文件

然後我甚至還沒有得到這一點,但我是否需要添加co de關閉它,或者只是點擊後退按鈕自動關閉它?

謝謝!

這裏是我的java文件

public class FC extends Activity { 

    WebView mWebView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 

     //this one line added for progress support 
     this.getWindow().requestFeature(Window.FEATURE_PROGRESS); 

     setContentView(R.layout.web); 

     //makes progress bar visible 
     getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 

     //get web view 
     mWebView = (WebView) findViewById(R.id.webWeb); 
     mWebView.getSettings().setJavaScriptEnabled(true); 
     mWebView.getSettings().setSupportZoom(true); 
     mWebView.getSettings().setBuiltInZoomControls(true); 
     mWebView.setInitialScale(45); 
     mWebView.loadUrl("http://www.chipmunkmobile.com"); 

     //sets the Chrome client 
     final Activity MyActivity = this; 
     mWebView.setWebChromeClient(new WebChromeClient() 
     { 
      public void onProgressChanged(WebView view, int progress) 
      { 
       //makes the bar disappear after URL is loaded, and changes string to Loading... 
       MyActivity.setTitle("Loading..."); 
       MyActivity.setProgress(progress * 100); 

       //return the app name after finish loading 
       if(progress == 100) 
        MyActivity.setTitle(R.string.app_name); 
      } 

     }); 

     //makes page stay in same web client 
     mWebView.setWebViewClient(new WebViewClient() { 
      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) { 
       view.loadUrl(url); 
       return false; 
      } 
     }); 


     //looks to see if connects 
     mWebView.setWebViewClient(new WebViewClient() { 
      public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
       //Toast.makeText(getApplicationContext(), "NO CONNECTION?\nVisit the Cyberspots in the SW and NW Halls to find out how to get on the free WiFi", 
        //Toast.LENGTH_LONG).show(); 

       //showDialog(0); 

       AlertDialog.Builder builder; 
       AlertDialog alertDialog; 

       Context mContext = getApplicationContext(); 
       LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); 
       View layout = inflater.inflate(R.layout.custom_dialog, 
         (ViewGroup) findViewById(R.id.layout_root)); 

       TextView text = (TextView) layout.findViewById(R.id.text); 
       text.setText("WHATEVER"); 
       ImageView image = (ImageView) layout.findViewById(R.id.imgid); 
       image.setImageResource(R.drawable.img); 

       builder = new AlertDialog.Builder(mContext); 
       builder.setView(layout); 
       alertDialog = builder.create(); 


      } 
     }); 
    } 

代碼下面是我在.xml文件

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/layout_root" 
    android:padding="10dp"> 
    <ImageView android:id="@+id/imgid" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_marginRight="10dp" 
     /> 
    <TextView android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:textColor="#FFF" 
     /> 

</LinearLayout> 

回答

0

而不是使用我只是用一個嵌入HTML錯誤消息的警報......我沒有找到一個解決的問題alertDialog

0

代碼添加到alertDialog.show()實際顯示該對話框的方法結束。

此外,您可能需要添加setNeutralButton("ok", new DialogInterface.OnClickListener() {...}並呼叫finish關閉OnClickListener中的對話框。

+0

感謝您嘗試,但崩潰的程序。任何其他建議? – SnowboardBruin

+0

它是如何使程序崩潰的?你可以發佈堆棧跟蹤嗎? –