我这里有一个非常奇怪的问题。无法弄清楚发生了什么。在我的应用程序中,我发生了以下情况:
奇怪的是,如果我没有弹出AlertDialog它可以正常工作。
代码是:
public class MyMapFragment extends Fragment implements LocationListener, GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener {
private GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//...
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(final Marker marker) {
AlertDialog alert = new AlertDialog.Builder(getActivity())
.setTitle("Confirmação")
.setMessage("Essa ação gastará 1 de energia")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UFVQuestUtils.user.setEnergyLeft(UFVQuestUtils.user.getEnergyLeft() - 1);
parent.navigationDrawerAdapter.notifyDataSetChanged();
Quest q = UFVQuestUtils.questMarkerMap.get(marker);
if (q != null) {
final Fragment fragment;
if (q instanceof GoToAndAnswerQuest) {
fragment = new GoToAndAnswerFragment();
} else {
fragment = new SeekAndAnswerFragment();
}
if (fragment != null) {
UFVQuestUtils.currentQuest = q;
UFVQuestUtils.currentMarker = marker;
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.content_frame, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
}
}
})
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
}).create();
alert.show();
}
});
感谢您的帮助。