MapFragment and the dreaded "Duplicate id" exception - how to use MapFragment in an AlertDialog

107 views Asked by At

So, I have the error described in this post:

I have searched SO and found several explainations on why I get this error:

and so on.

My problem is that I think I dont fully understand how Fragments are to be used (yes, I have read the part on Fragments on the Android dev sites), and more specifically, how to solve my specific problem.

I have a fragment called "BookingList". That BookingList has rows with bookings, and each row can be clicked. When I click, I show a Dialog with some info about that booking, and a map. The list is a ListView and the onClickListener is like this:

public class BookingList extends Fragment {

// ... code code code

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{
       // ... code

       // ... code

       list.setOnItemClickListener(new AdapterView.OnItemClickListener() 
       {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id)
          {
              BookingLight bl = (BookingLight)bookingRowAdapter.getRow(position);
              String name = bl.Customer.Firstname + " " + bl.Customer.Lastname;
              Toast.makeText(getActivity(), "Öppnar " + name, Toast.LENGTH_SHORT).show();

              Handler myHandler = new Handler(); 
              myHandler.postDelayed(new Runnable()
              {
                  @Override
                  public void run()
                  {
                      View detailsView = infl.inflate(R.layout.booking_details, null);
                      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                      builder.setView(detailsView);
                      builder.create().show();
                  }
              }, 500);
          }
      });

As you can see, I simply inflate the booking_details which is a simple View, containing a MapFragment.

The second time I click one of these rows, I get the exception mentioned above. Since the view is not a Fragment on its own (its just a View so far), I am not sure how to avoid this exception.

I have a vague idea to use FragmentManager, but Im not sure exactly how.

Can someone explain this to me perhaps?

0

There are 0 answers