在我的模拟器出现几秒钟后,在选择一个选项之前,我正在经历一个意外崩溃的。你知道问题出在哪里吗?
我有一个带有几个对象的ListView。在LongClick上将出现一个小菜单。通过选择“删除”选项,我希望出现一个AlertDialog,并询问用户是否确定他在做什么。
@Override
public boolean onContextItemSelected(MenuItem item) {
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.rename:
// rename the entry in the list
return true;
case R.id.delete:
// confirmation popup before deleting
new AlertDialog.Builder(getActivity()).setTitle(R.string.app_name).setMessage("Are you sure you want to delete this package?").setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// Really delete the package
}
}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// Do nothing
}
}).show();
return true;
default:
return super.onContextItemSelected(item);
}
}就在坠机之前,我在日志中得到了一条消息:
警告:错误的通用指针0x7f64d97be818
发布于 2016-11-07 23:33:31
很明显,问题就是AVD本身!我用的是一个坏了的系统图像。再下载一次解决了问题。
发布于 2016-11-07 22:36:55
像这样用它也许能解决坠机。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.delete) {
return true;
}
return super.onOptionsItemSelected(item);
}https://stackoverflow.com/questions/40475553
复制相似问题