动作条不工作动作、工作

2023-09-12 03:19:02 作者:起雾森林

我需要相关的操作栏工作的指导。其实点击一个操作栏菜单项。当前活动必须移到另一个活动。但它什么都不做。甚至没有任何错误。我用下面的code:

  @覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    MenuInflater充气= getMenuInflater();
    inflater.inflate(R.menu.mnew1,菜单);
    返回super.onCreateOptionsMenu(菜单);
}

@覆盖
公共布尔onOptionsItemSelected(菜单项项){
    //操作栏上的项目手柄presses
    开关(item.getItemId()){
        案例R.id.home:
            尝试 {
                OpenSearch的();
            }赶上(IOException异常E){
                e.printStackTrace();
            }
            返回true;
        默认:
            返回super.onOptionsItemSelected(项目);
        }
    }

私人无效的OpenSearch()抛出IOException异常{
    VAL =地址(location.getLatitude(),location.getLongitude());
    意图int​​nt =新的意图(getApplicationContext(),SendSms.class);
    intnt.putExtra(]辛,VAL);
    startActivity(intnt);
}
 

解决方案

这code是完美的。没有与此code任何问题。动作条按钮不能正常工作,由于空值是receiving..and null值是只是因为一些硬件issues..nothing不对的code谢谢

6个动作帮你放松,工作锻炼两不耽误

I need some guidance regarding the working of Action bar. Actually clicking on a Action bar MenuItem. Current activity must be moved to another activity. But it's doing nothing. Not even any error. I used following code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mnew1, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
        case R.id.home:
            try {
                openSearch();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

private void openSearch() throws IOException{
    val=address(location.getLatitude(), location.getLongitude());
    Intent intnt=new Intent(getApplicationContext(),SendSms.class);
    intnt.putExtra("loct", val);
    startActivity(intnt); 
}

解决方案

this code is perfect. There is not any problem with this code. Actionbar button was not working due to null value it is receiving..and null value was just because of some hardware issues..nothing wrong with this code thanks

 
精彩推荐
图片推荐