您好我添加了菜单文件,有3个菜单项:
1)菜单图钉,
2)发送回复和
3)添加笔记。
发送回复,添加备注工作正常但是,当删除针脚的注释时,它无法正常工作。我附上了以下代码。
请建议我任何解决方案。当我将发送回复的代码粘贴到pin_menu案例以进行测试时,它无效。
Log cat没有显示任何内容。我在点击pin_menu时添加了吐司,它没有显示。请建议我解决。
我还尝试在XML文件中添加一个额外的菜单,并添加了与pin_menu相同但不起作用的代码。没有显示log cat,toast。所以很难调试。发送回复和添加注释,但两者都工作正常。
代码如下:
<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);
}
}
答案 0 :(得分:0)
我认为您在错误的地方使用此注释代码。您应该在返回之前使用它,在开关盒结构中。如果你想点击引脚触发它。这是更新的代码;
@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);
}
}