我是初学者。 代码仅在android 6和upper上运行。 代码运行良好,有6个警告,但我想在Menu_Main.xml 6行中删除这6个警告,例如带有onClick = itemClick的行。
我该怎么做才能摆脱这些警告?请帮助我。
[]interface {}{main.UserCommand{User:"u1", Info:"i1"}, main.UserCommand{User:"u2", Info:"i2"}}
[]interface {}{main.ProductCommand{Name:"n1", Quantity:1}, main.ProductCommand{Name:"n2", Quantity:2}}
package com.example.sky.my13application;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean itemClick(MenuItem item){
Toast.makeText(this,item.getTitle() ,Toast.LENGTH_LONG).show();
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.sky.my13application.MainActivity">
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="@string/app_name1"
android:onClick="itemClick"
/>
<item android:title="@string/app_name2"
android:onClick="itemClick"
/>
<item android:title="@string/app_name3"
android:onClick="itemClick"
>
<menu>
<item android:title="@string/app_name4"
android:onClick="itemClick"
/>
<item android:title="@string/app_name5"
android:onClick="itemClick"
/>
</menu>
</item>
</menu>