点击菜单没反应,如下代码。Log.i("", "----add---"),根本没执行到。log.cat显示:Window already focused, ignoring focus gain of,请高手帮忙.不知道为什么,在有些Activity中添加菜单,又可以。
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
menu.add(0, 0, 0, R.string.addSong);
menu.add(0, 1, 1, R.string.deleteSong);
return true;
}

public boolean onOptionItemSelected(MenuItem item){
Log.i("", "----add---");
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case 0:
Log.i("", "----add---");
Intent mp3intent = new Intent();
mp3intent.setClass(PlayList.this, MP3List.class);
startActivity(mp3intent);
myCursor.close();
db.close();
PlayList.this.finish();
break;
case 1:

break;
}
return true;
}

解决方案 »

  1.   

    求助,正在初学android,也碰到类似问题,Window already focusedpublic boolean onContextItemSelected(MenuItem item) { 
    AdapterView.AdapterContextMenuInfo menuinfo = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
    switch(item.getItemId()) {        
    case EDITE_ID:  
    Cursor c = mNotesCursor;
    c.moveToPosition(menuinfo.position);
    editNote(c, menuinfo.id);
    return true;       
    case DELETE_ID:
    long b = menuinfo.id;
    boolean a = mDbHelper.deleteNote(b);
    fillData();
    return true;
    }                
    return super.onContextItemSelected(item);    
    }
    每次第一个case即EDITE_ID都可以正常进去,但点击上下文菜单第二项,第二个case即DELETE_ID从来都没进去过,也根本没有执行这个函数。到底是怎么回事啊。
      

  2.   

    public boolean onOptionItemSelected(MenuItem item){
    }
    昨天才发现,onOptionItemSelected这个函数名根本不是重写菜单响应的函数名(onOptionsItemSelected),少了个S,等于是定义了一个新的函数,所以没起作用,也没报错。
    粗心...自残ing...
      

  3.   

    楼上说的:Window already focused,这个本来就是一个警告级别的信息。
    若出现没有响应,出现Window already focused信息,那么请检查代码,肯定是代码的问题。
    1、函数名是否确实是重写的函数名,如我犯的错误。
    2、switch(item.getItemId()) {   case EDITE_ID:  //去打印一下,看是否执行到}
      

  4.   

    boolean a = mDbHelper.deleteNote(b);
    fillData();
    return true;//这里有问题吧。这里就return true了,那么return     super.onContextItemSelected (item);这条代码应该执行不到了吧,而这条语句肯定是要执行的。   
    }   
    return super.onContextItemSelected(item);   
    }
      

  5.   

    我晕死,我也跟LZ一样粗心了,自残-ing。
      

  6.   

    我也是出现了相同问题~Window already focused, ignoring focus gain of~求解啊~public boolean onCreateOptionsMenu(Menu menu) {
         menu.add(0, UPDATE, 1, R.string.ktvlist_update);
         menu.add(0, ABOUT, 2, R.string.ktvlist_about);
    return super.onCreateOptionsMenu(menu);
    }
        
        @Override
    public boolean onOptionsItemSelected(MenuItem item) {
         if(item.getItemId() == UPDATE){
         String xml = downloadXML("http://192.168.1.100:139/KTV/resources.xml");
         System.out.println("-->" + xml);
         }else if(item.getItemId() == ABOUT){
        
         }
    return super.onOptionsItemSelected(item);
    }       private String downloadXML(String urlStr){
    HttpDownloader httpDownloader = new HttpDownloader();
    String result = httpDownloader.download(urlStr);
    return result;

      

  7.   

    我也碰到了这个问题经过仔细检查 
    是自己把switch中的getItemId写错了  唉  自虐~~
      

  8.   

    [Quote=引用 3 楼 llxwd 的回复:]
    每次第一个case即EDITE_ID都可以正常进去,但点击上下文菜单第二项,第二个case即DELETE_ID从来都没进去过,也根本没有执行这个函数。到底是怎么回事啊。
    [Quote]我也遇到类似问题了,求解释。
      

  9.   

      /**  
         * 当菜单某个选项被点击时调用该方法    
         */  
        @Override  
        public boolean onContextItemSelected(MenuItem item) {  
         Log.i("cmcmcmccm", "onContextItemSelected" + item.toString());
            switch(item.getItemId()){  
            case MEUN_IS_ENCRYPT:  
                Log.i("cmcmcmcm", 1 + "");
                break;  
            case MENU_CANCEL:  
              Log.i("cmcmcmcm", 2 + "");  
                break;  
            case MENU_IS_MODIFY:  
              Log.i("cmcmcmcm", MEUN_IS_ENCRYPT + "");  
                break;  
            case MENU_CANCEL_ENCRYPT:  
              Log.i("cmcmcmcm", MEUN_IS_ENCRYPT + "");  
                break;  
             
            }  
            return super.onContextItemSelected(item);  
        } 报同样的错误,什么原因