mianactivity
public class MainActivity extends Activity {
//private Spinner typeSpn;
private WebView engine;
public WebView getEngine() {
engine.setFocusable(true);
return engine;
}
private PopupWindow pop;
private boolean b;
Handler handler = new Handler();  

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TelephonyManager tm = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
String sim = tm.getSimSerialNumber();
String phone = tm.getLine1Number();
System.out.println(sim);
engine = (WebView)findViewById(R.id.webInfo);
engine.getSettings().setJavaScriptEnabled(true);
//engine.
//得到websetting
WebSettings websetting = engine.getSettings();  
//添加JS支持
websetting.setJavaScriptEnabled(true);  
engine.loadUrl("http://192.168.5.244:8080/AndroidCoupon/main.jsp?myflag="+"18073810337");
engine.setWebViewClient(new MainWebViewClient());
/*** 
         *webChromeClient是一个比较神奇的东西,其里面提供了一系列的方法, 
         *分别作用于我们的javascript代码调用特定方法时执行,我们一般在其内部 
         *将javascript形式的展示切换为android的形式。  
         * 例如:我们重写了onJsAlert方法,那么当页面中需要弹出alert窗口时,便 
         * 会执行我们的代码,按照我们的Toast的形式提示用户。 
         */  
class MyWebChromeClient extends WebChromeClient {  
            @Override  
            public boolean onJsAlert(WebView view, String url, String message,  
                    JsResult result) {  
             System.out.println("check2");
             if(message.length()!=0){
             Toast.makeText(getApplicationContext(), message,  
             Toast.LENGTH_LONG).show();
             result.cancel();
             return true;
             }
               return false;
            }
            
            @Override
            public boolean onJsConfirm(WebView view, String url,
             String message, JsResult result) {
             if(message.equals("fileUp"))
         {
             showPop();
                 return true;
         }
             return false;
            }
        }  

engine.setWebChromeClient(new MyWebChromeClient());

 /* 
         * 为javascript提供一个回调的接口,这里要注意,一定要在单独的线程中实现,要不会阻塞线程的 
         * addJavascriptInterface(Object obj, String interfaceName) 
         * obj代表一个java对象,这里我们一般会实现一个自己的类,类里面提供我们要提供给javascript访问的方法 
         * interfaceName则是访问我们在obj中声明的方法时候所用到的js对象,调用模式为window.interfaceName.方法名()  
         * 通过webView.loadUrl("javascript:xxx")方式就可以调用当前网页中的名称 
         * 为xxx的javascript方法 
         */  

private class MainWebViewClient extends WebViewClient {
// 在WebView中而不是默认浏览器中显示页面
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
} } @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if ((keyCode == KeyEvent.KEYCODE_BACK) && engine.canGoBack()&&b==false) {
engine.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
} @Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
System.out.println(engine.getId());
}

//当客户点击MENU按钮时,调用该方法
    @Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
     //groundId是菜单所处的组的名字
     //itemId是当前菜单的id
     //order当前排序
     //title是显示的内容
     menu.add(0, 1, 1, R.string.main);
     menu.add(0, 2, 2,R.string.mysetting);
     menu.add(0, 3, 3, R.string.myCoupon);
     menu.add(0, 4, 4, R.string.login);
     menu.add(0, 5, 5, R.string.register);
     menu.add(0, 6, 6, R.string.manage);
     menu.add(0, 7, 7, R.string.exit);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
// TODO Auto-generated method stub
if(item.getItemId() == 1){
engine.loadUrl("http://192.168.5.244:8080/AndroidCoupon/main.jsp");
}else if(item.getItemId() == 2){
engine.loadUrl("http://192.168.5.244:8080/AndroidCoupon/mysetting.jsp");
}else if(item.getItemId() == 3){
engine.loadUrl("http://192.168.5.244:8080/AndroidCoupon/mycoupon.jsp");
}else if(item.getItemId() == 4){
engine.loadUrl("http://192.168.5.244:8080/AndroidCoupon/login.jsp");
}else if(item.getItemId() == 5){
engine.loadUrl("http://192.168.5.244:8080/AndroidCoupon/register.jsp");
}else if(item.getItemId() == 7){
finish();
}
return super.onOptionsItemSelected(item);
}
   
   @Override    
   protected void onDestroy() {    
       super.onPause();   
       //System.exit(0);    
       android.os.Process.killProcess(android.os.Process.myPid());    
   }
   
   private void showPop()
   {
   engine.requestFocus();
   ColorDrawable dw = new ColorDrawable(Color.BLACK);
   if(pop==null)
   {
   View view = this.getLayoutInflater().inflate(R.layout.upload, null);
   pop = new MyPopupwindow(view, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, this);
   pop.setFocusable(true);
   pop.setBackgroundDrawable(dw);
   pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
public void onDismiss() {
pop.setFocusable(false);
engine.loadUrl("www.baidu.com");
engine.requestFocus();
pop.update();
}
});
   pop.update();
   }
   pop.showAtLocation(findViewById(R.id.webInfo), Gravity.CENTER, 0, 0);  
   b=true;
   }
   
   
}

解决方案 »

  1.   

    自定义的popupwindowpublic class MyPopupwindow extends PopupWindow {
    private LinearLayout layout;    //总的布局  
    String thisUrl = ""; //当前访问的URL
    //指点上传文件的类型
    public enum TargetFileTypes{
    File,
    Folder,
    All,
    }
    //需要用到的控件
    Button btnOK;
    Button btnUp;
    EditText txtPath;
    ListView lvFile;
    TargetFileTypes TargetFileType; //声明枚举
    boolean IsSingle; //是否选中
    Pattern FilePattern;//文件过滤正则表达式
    String StartPath;//开始路径
    String CurrentPath;//当前路径
    ArrayList<String> listName = new ArrayList<String>();
    ArrayList<File> listFile = new ArrayList<File>();
    ArrayAdapter<String> adapter;
    Activity ac;
    WebView webInfo;
    FileFilter TargetFilter = new FileFilter() {
    public boolean accept(File file) {
    if(TargetFileType==TargetFileTypes.Folder && file.isFile()){
    return false;
    }
    if(FilePattern !=null && file.isFile()){
    return FilePattern.matcher(file.getName()).find();
    }
    return true;
    }
    };

    public MyPopupwindow(View view,int layout,int layout2,Activity mainac)
    {
    super(view,layout,layout2);
    this.ac=mainac;
    InitialInputData();
        InitialControls(view);
        BindList();
    }

    @Override
    public void showAtLocation(View parent, int gravity, int x, int y) {
    webInfo = (WebView)parent;
    super.showAtLocation(parent, gravity, x, y);

    }
     /**
         * 取得Intent传来的数据
         */
        public void InitialInputData(){
         Intent i = ac.getIntent();
         IsSingle = i.getBooleanExtra("Single", false);
         StartPath = i.getStringExtra("Path");
         if(TextUtils.isEmpty(StartPath)){
         StartPath="/";
         }
         CurrentPath=StartPath;
         String s = i.getStringExtra("Type");
         if(TextUtils.isEmpty(s)){
         TargetFileType=TargetFileTypes.All;
         }else{
         TargetFileType = TargetFileTypes.valueOf(s);
         }
         s=i.getStringExtra("Pattern");
         if(TextUtils.isEmpty(s)==false){
         FilePattern = Pattern.compile(s,Pattern.CASE_INSENSITIVE);
         }
        }
        
        /*
         * 列表项点击
         */
        public void ListItem_Click(int index){
         File f=listFile.get(index);
         int i = lvFile.getCheckedItemIds().length;
    if(f.isFile()){
    if(i==0)
    {
    return;
    }
    txtPath.setText(f.getPath());
    return;
    }
    CurrentPath=f.getPath();
    if(CurrentPath.endsWith("/")==false){
    CurrentPath+="/";
    }
    BindList();
        }
        
        /**
         * 向上
         */
        public void btnUp_Click(){
    if(CurrentPath.equals("/")){
    this.dismiss();
    return;
    }
    int p = CurrentPath.lastIndexOf("/", CurrentPath.length()-2);
    CurrentPath = CurrentPath.substring(0, p+1);
    BindList();
        }
        
        @Override
        public void dismiss() {
         super.setFocusable(false);
         super.update();
         webInfo.setFocusable(true);
         webInfo.requestFocus();
         super.dismiss();
         super.setFocusable(false);
         super.update();
         webInfo.setFocusable(true);
         webInfo.requestFocus();
        }
        
        /**
         * 确定
         */
        public void btnOK_Click(){
    Intent intent = ac.getIntent();
    // 如果是其他程序激活此活动
    if(Intent.ACTION_MAIN.equals(intent.getAction())==false){
    ArrayList<String> listResult = new ArrayList<String>();
    SparseBooleanArray ps = lvFile.getCheckedItemPositions();
    int size =listFile.size();
    for(int i =0; i<size; i++){
    if(ps.get(i)){
    listResult.add(listFile.get(i).getPath());
    }
    }
    Intent i=new Intent();
    i.putStringArrayListExtra("Result", listResult);
    ac.setResult(Activity.RESULT_OK, i);
    }
        }
        
        /**
         * 清除选中
         */
        public void chkAll_Click(){
    boolean value = false;
    for(int i=0; i<listName.size(); i++){
    lvFile.setItemChecked(i, value);

    }
        }
        
        /**
         * 绑定文件列表
         */
        public void BindList(){
            File file =new File(CurrentPath);
            File[] files = file.listFiles(TargetFilter);
            if(files==null){
             return;
            }
    listName.clear();
    listFile.clear();
    txtPath.setText(CurrentPath);
            for(File f : files){
             listName.add(f.getName());
             listFile.add(f);
            }
            if(adapter==null){
             int layoutId=IsSingle?android.R.layout.simple_list_item_single_choice:android.R.layout.simple_list_item_multiple_choice;
             adapter=new ArrayAdapter<String>(ac, layoutId, android.R.id.text1, listName); 
             lvFile.setAdapter(adapter);
            }else{
             adapter.notifyDataSetChanged();
            }
            lvFile.scrollTo(0, 0);
            //清空选中
            chkAll_Click();
        }
        
        /**
         * 初始化控件
         */
        private void InitialControls(View view){
        
         btnOK= (Button)(view.findViewById(R.id.btnOK));
         btnOK.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
         btnOK_Click();
    }
    });
         btnUp=(Button)(view.findViewById(R.id.btnUp));
         btnUp.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {   
    btnUp_Click();
    }
    });
         txtPath=(EditText)(view.findViewById(R.id.txtPath));
         lvFile=(ListView)(view.findViewById(R.id.lvFile));
         lvFile.setChoiceMode(IsSingle?ListView.CHOICE_MODE_SINGLE:ListView.CHOICE_MODE_MULTIPLE);
         lvFile.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
    long arg3) {
    ListItem_Click(arg2);
    }

    });
        
        }
    }问题来了,我从Activity中显示popupwindow,当popupwindow.dismiss()以后调用webview.load("http://www.baidu.com")无效。并且整个webview无效。求解决方法!
      

  2.   

    代码太多了!有什么出错信息不?
    http://blog.csdn.net/ch_984326013/article/details/6674629
      

  3.   

    没有任何错误信息。
    就是当popupwindow dismiss以后  WEBVIEW就无法使用了
      

  4.   

    android 系统中webkit的问题,我现在也正在解决这个问题
    三星的最新手机就没有这些问题
    注:我们是做android系统的,不是应用的