亲爱的,我们可以用菜单项的onclick使用XML。如下图所示。我尝试过,但它不工作。
Dear can we use onclick with menu item in xml. like below .i tried it but its not working.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/logout"
android:onClick="onLogOut"
android:title="@string/logout">
</item>
Java的code:
Java Code :
public void onLogOut(MenuItem v) {
Utility.LogError(TAG, "onLogOut Clicked");
Toast.makeText(this, "onLogOut", Toast.LENGTH_SHORT).show();
}
}
onLogOut不被调用....
onLogOut is not get called....
使用
android:onClick="onLogOutClick"
而不是
android:onClick="@string/onLogOutClick"
对于菜单项的onclick加入
for adding onclick with menu item
和而在Java中,我们应该为这个点击数方法
and And in Java we should write the method for this onlick
public void onLogOutClick(MenuItem item) {
Log.d("MenuItem", "onLogOutClick :: "+item.getItemId());
}
下一篇:从SD卡文件路径路径、文件、SD