简体   繁体   English

操作栏中的菜单项不起作用

[英]Menu Item in action bar not working

Hi I added the menu file ,there are 3 Menu Items: 嗨,我添加了菜单文件,有3个菜单项:

1) Menu Pin, 1)菜单针

2) Send Reply and 2)发送回复并

3) Add Notes. 3)添加注释。

Send Reply , Add Notes are working fine but, when removed comment for pin, it is not working. 发送回复,添加注释可以正常工作,但是当删除图钉注释时,它将无法正常工作。 I attached the code below. 我附上了下面的代码。

Please suggest me any solution. 请给我建议任何解决方案。 When I paste the code of Send Reply to pin_menu case for testing purpose it is not working. 当我出于测试目的将“发送答复”的代码粘贴到pin_menu情况时,它不起作用。

Log cat doesn't show anything.I added the toast on click of pin_menu it doesn't show.Please suggest me solution. 日志猫什么也没显示。我在未显示的pin_menu单击上添加了吐司。请给我建议解决方案。

I also tried to add one extra menu in XML file and added the code same as the pin_menu but not worked. 我还尝试在XML文件中添加一个额外的菜单,并添加了与pin_menu相同的代码,但是没有用。 Doesn't show log cat ,toast. 不显示日志猫,吐司。 So that hard to debug.Same for Send Reply and Add Note but both are working fine. 很难调试,与发送回复和添加注释相同,但都可以正常工作。

Code is as below: 代码如下:

 <item android:id="@+id/menu_pin"
      android:icon="@drawable/pin"
      android:title="@string/pin"
      android:showAsAction="never" 
      />

<item android:id="@+id/menu_send_reply"
      android:icon="@drawable/send"
      android:title="@string/send_reply"
      android:showAsAction="never" 
      />

<item android:id="@+id/menu_add_note"
      android:icon="@drawable/add_note"
      android:title="@string/add_note"
      android:showAsAction="never" 
       />

                            @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                    // TODO Auto-generated method stub
                    MenuInflater menuInflater = getMenuInflater();
                    menuInflater.inflate(R.menu.ticket_properties_menu, menu);
                    return true;
                }

                @Override
                public boolean onOptionsItemSelected(MenuItem item) {

                    Log.d("DATA ","Item ID "+item.getItemId());
                    // TODO Auto-generated method stub
                    switch (item.getItemId())
                    {
                    case R.id.menu_add_note:

                        Intent i3 = new Intent(Ticket_properties.this,Add_note.class);
                        i3.putExtra("ID", Ticket_id);
                        i3.putExtra("client_id", client_id);
                        startActivity(i3);
                        return true;

                    case R.id.menu_send_reply:

                        Intent reply= new Intent(Ticket_properties.this,Send_reply.class);
                        reply.putExtra("ticket_id", Ticket_id);
                        reply.putExtra("title", Ticket_title);
                        reply.putExtra("dept_id", tv_dept_id.getText());
                        reply.putExtra("Ticket_hash", Ticket_hash);
                        reply.putExtra("filter_id",filter_id);
                        startActivity(reply);
                        return true;

                    case R.id.menu_pin:

                        Intent reply1= new Intent(Ticket_properties.this,Send_reply.class);
                        reply1.putExtra("ticket_id", Ticket_id);
                        reply1.putExtra("title", Ticket_title);
                        reply1.putExtra("dept_id", tv_dept_id.getText());
                        reply1.putExtra("Ticket_hash", Ticket_hash);
                        reply1.putExtra("filter_id",filter_id);
                        startActivity(reply1);
                        return true;

                        /*
                      String PIN_URL=op.getUrl(Ticket_properties.this,"ticket", "add_pinup","&vis_ticket_id=124");
                      JSONArray pin_result = JSONfunctions.getJSONfromURL(PIN_URL+"&vis_encode=json",Ticket_properties.this);
                      String result =pin_result.toString();
                      if(result.equals("[\"success\"]"))
                      {             
                            Operation.showToast(getApplicationContext(),R.string.pinned);           
                      }
                      */

                  default:
                        return super.onOptionsItemSelected(item);
                    }


                }

Well i think you are using this commented code on the wrong place. 好吧,我认为您在错误的位置使用了此注释代码。 You should use it before return, in the switch case structure. 您应该在开关外壳结构中返回之前使用它。 If you want to trigger it on pin clicked. 如果要触发,请单击别针。 Here is the updated code; 这是更新的代码;

@Override
            public boolean onCreateOptionsMenu(Menu menu) {
                // TODO Auto-generated method stub
                MenuInflater menuInflater = getMenuInflater();
                menuInflater.inflate(R.menu.ticket_properties_menu, menu);
                return true;
            }

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {

                Log.d("DATA ","Item ID "+item.getItemId());
                // TODO Auto-generated method stub
                switch (item.getItemId())
                {
                case R.id.menu_add_note:

                    Intent i3 = new Intent(Ticket_properties.this,Add_note.class);
                    i3.putExtra("ID", Ticket_id);
                    i3.putExtra("client_id", client_id);
                    startActivity(i3);
                    return true;

                case R.id.menu_send_reply:

                    Intent reply= new Intent(Ticket_properties.this,Send_reply.class);
                    reply.putExtra("ticket_id", Ticket_id);
                    reply.putExtra("title", Ticket_title);
                    reply.putExtra("dept_id", tv_dept_id.getText());
                    reply.putExtra("Ticket_hash", Ticket_hash);
                    reply.putExtra("filter_id",filter_id);
                    startActivity(reply);
                    return true;

                case R.id.menu_pin:

                                          String PIN_URL=op.getUrl(Ticket_properties.this,"ticket", "add_pinup","&vis_ticket_id=124");
                  JSONArray pin_result = JSONfunctions.getJSONfromURL(PIN_URL+"&vis_encode=json",Ticket_properties.this);
                  String result =pin_result.toString();
                  if(result.equals("[\"success\"]"))
                  {             
                        Operation.showToast(getApplicationContext(),R.string.pinned);           
                  }
                    Intent reply1= new Intent(Ticket_properties.this,Send_reply.class);
                    reply1.putExtra("ticket_id", Ticket_id);
                    reply1.putExtra("title", Ticket_title);
                    reply1.putExtra("dept_id", tv_dept_id.getText());
                    reply1.putExtra("Ticket_hash", Ticket_hash);
                    reply1.putExtra("filter_id",filter_id);
                    startActivity(reply1);
                    return true;

              default:
                    return super.onOptionsItemSelected(item);
                }


            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM