动作条不工作 [英] ActionBar not working

查看:93
本文介绍了动作条不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于动作条不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆