0

I Have my MapsActivity, that has a onCreateMethod() as

setContentView(R.layout.activity_maps);

I called a dialog box that can overlay the current activity for a while as

Dialog dialog = new Dialog(MapsActivity.this);
dialog.setContentView(R.layout.dialog);
dialog.setCancelable(false);
dialog.show();

It refers to dialog.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:gravity="center">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Enter Destination Name"
            android:id="@+id/textView8" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:gravity="center">
        <fragment
            android:id="@+id/place_autocomplete_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
    </LinearLayout>
</LinearLayout>

I want my program to refer from MapsActivity to R.id.place_autocomplete_fragment in dialog.xml

I Tried using R.id.place_autocomplete_fragment but it didn't work.

So how do i do this? HELPPP

2 Answers2

0

Try not having your fragment written into the xml directly. Instead allocate a holder view for your fragment, and then use the Fragment Manager to add that Fragment into that space Programmatically.

Athos
  • 681
  • 2
  • 7
  • 14
  • what do you mean? I am not that good with android just average :P – Lovely Princess Mar 02 '16 at 15:06
  • I'm assuming that you have a fragment that wrap's Google's Autocomplete Places. I think you might get a better sense of how to set this up by checking out this stackoverflow: http://stackoverflow.com/questions/30089123/google-places-autocomplete-android-fragment You can see that they are replacing a view with that of the Fragment they want to use using the FragmentManager (and Fragment Transaction). – Athos Mar 02 '16 at 15:23
  • nope thats not the problem what i want is that a layout different from the .java be referred. :P – Lovely Princess Mar 02 '16 at 16:32
0

You can just do

dialog.findViewById(R.id.place_autocomplete_fragment)

You will get the instance in MapsActivity itself. Your question was not that clear to me, so hope this answer helps.

ranjitzade
  • 541
  • 5
  • 14