我可以看到在这里明白我做错了什么。
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
Map<String, String> data = (Map<String, String>) getListView().getItemAtPosition(info.position);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
String admin = preferences.getString("Admin", null);
String user_ids = preferences.getString("userID", null);
menu.setHeaderTitle("Options");
menu.add(0, profile, 0, "Show Profile");
if (admin.equals("Admin")){
menu.add(0, add, 0, "Add Friend");
menu.add(0, pm, 0, "Send PM");
menu.add(0, warn, 0, "Send Warning");
menu.add(0, edit, 0, "Edit Post");
menu.add(0, delete, 0, "Delete Post");
menu.add(0, block, 0, "Block User");
}else if (data.get("pid").equals(user_ids)){
menu.add(0, edit, 0, "Edit Post");
}else{
menu.add(0, add, 0, "Add Friend");
menu.add(0, pm, 0, "Send PM");
menu.add(0, warn, 0, "Send Warning");
menu.add(0, block, 0, "Block User");
}
}
错误输出
view.showContextMenu();
但如果我注释掉IF ELSE语句就行了。困惑。