2011-09-22 72 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

它是如何使程序崩溃的?你可以发布堆栈跟踪吗? –