How should I get access to a custom view that is in a fragment layout?How to get an enum value from a string value in Java?When and how should I use a ThreadLocal variable?How to get the absolute coordinates of a viewHow to align views at the bottom of the screen?How to hide the title bar for an Activity in XML with existing custom themeGet root view from current activityHow to get the build/version number of your Android application?How do I get the currently displayed fragment?How to determine when Fragment becomes visible in ViewPagerHow to create RecyclerView with multiple view type?

Writing an ace/aro character?

Need a non-volatile memory IC with near unlimited read/write operations capability

Category-theoretic treatment of diffs, patches and merging?

Would a Nikon FG 20 film SLR camera take pictures without batteries?

Is there a method for differentiating informative comments from commented out code?

Number of states in taxi environment (Dietterich 2000)

I make billions (#6)

Performance issue in code for reading line and testing for palindrome

What kind of Chinook helicopter/airplane hybrid is this?

What factors could lead to bishops establishing monastic armies?

Is it ok for parents to kiss and romance with each other while their 2- to 8-year-old child watches?

Compressed gas thruster for an orbital launch vehicle?

Four ships at the ocean with the same distance

US citizen traveling with Peruvian passport

Is it possible to complete a PhD in CS in 3 years?

Did Rabbi Akiva accept arguments from ignorance?

Password Hashing Security Using Scrypt & Argon2

First Entry Member State schengen visa

Conditions for Roots of a quadratic equation at infinity

Adjust the Table

Why does the Antonov AN-225 not have any winglets?

Publishing papers seem natural to many, while I find it really hard to think novel stuff to pursue till publication. How to cope up with this?

Why was such an unrevealing title originally chosen and then changed for some International markets?

Why does Trump want a citizenship question on the census?



How should I get access to a custom view that is in a fragment layout?


How to get an enum value from a string value in Java?When and how should I use a ThreadLocal variable?How to get the absolute coordinates of a viewHow to align views at the bottom of the screen?How to hide the title bar for an Activity in XML with existing custom themeGet root view from current activityHow to get the build/version number of your Android application?How do I get the currently displayed fragment?How to determine when Fragment becomes visible in ViewPagerHow to create RecyclerView with multiple view type?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a fragment whose layout consists of a custom view (MyCanvasView) and a button. I am trying to access a variable through a getter method in the MyCanvasView class. I am able to access the button to make an OnClickListener, but trying to access the custom view the same way doesn't work. vMapView remains null. How can I get access to the custom view from the fragment that contains it?



In fragment java file:



@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
View v = inflater.inflate(R.layout.select_anchor, container, false);

Button btnSubmitAnchor = (Button) v.findViewById(R.id.btn_submit_anchor);
MyCanvasView vMapView = (MyCanvasView) v.findViewById(R.id.anchor_selection_view);

btnSubmitAnchor.setOnClickListener((view) - >

receivedAnchor = vMapView.getTempAnchor();
try
Log.i(TAG, "Received anchor:n" + receivedAnchor.getName());
catch (Exception e)
Log.i(TAG, "no anchor was received");

);

return v;



In MyCanvasView.java:



public Anchor getTempAnchor() 
return tempAnchor;



In select_anchor.xml:



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

<view
android:id="@+id/anchor_selection_view"
class="com.decawave.argomanager.ui.view.MyCanvasView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
/>

<Button
android:id="@+id/btn_submit_anchor"
style="@style/MtrlBorderlessButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_margin="5dp"
android:text="@string/btn_submit_anchor" />


</RelativeLayout>









share|improve this question






























    0















    I have a fragment whose layout consists of a custom view (MyCanvasView) and a button. I am trying to access a variable through a getter method in the MyCanvasView class. I am able to access the button to make an OnClickListener, but trying to access the custom view the same way doesn't work. vMapView remains null. How can I get access to the custom view from the fragment that contains it?



    In fragment java file:



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
    View v = inflater.inflate(R.layout.select_anchor, container, false);

    Button btnSubmitAnchor = (Button) v.findViewById(R.id.btn_submit_anchor);
    MyCanvasView vMapView = (MyCanvasView) v.findViewById(R.id.anchor_selection_view);

    btnSubmitAnchor.setOnClickListener((view) - >

    receivedAnchor = vMapView.getTempAnchor();
    try
    Log.i(TAG, "Received anchor:n" + receivedAnchor.getName());
    catch (Exception e)
    Log.i(TAG, "no anchor was received");

    );

    return v;



    In MyCanvasView.java:



    public Anchor getTempAnchor() 
    return tempAnchor;



    In select_anchor.xml:



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

    <view
    android:id="@+id/anchor_selection_view"
    class="com.decawave.argomanager.ui.view.MyCanvasView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:layout_centerVertical="true"
    />

    <Button
    android:id="@+id/btn_submit_anchor"
    style="@style/MtrlBorderlessButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_margin="5dp"
    android:text="@string/btn_submit_anchor" />


    </RelativeLayout>









    share|improve this question


























      0












      0








      0








      I have a fragment whose layout consists of a custom view (MyCanvasView) and a button. I am trying to access a variable through a getter method in the MyCanvasView class. I am able to access the button to make an OnClickListener, but trying to access the custom view the same way doesn't work. vMapView remains null. How can I get access to the custom view from the fragment that contains it?



      In fragment java file:



      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
      View v = inflater.inflate(R.layout.select_anchor, container, false);

      Button btnSubmitAnchor = (Button) v.findViewById(R.id.btn_submit_anchor);
      MyCanvasView vMapView = (MyCanvasView) v.findViewById(R.id.anchor_selection_view);

      btnSubmitAnchor.setOnClickListener((view) - >

      receivedAnchor = vMapView.getTempAnchor();
      try
      Log.i(TAG, "Received anchor:n" + receivedAnchor.getName());
      catch (Exception e)
      Log.i(TAG, "no anchor was received");

      );

      return v;



      In MyCanvasView.java:



      public Anchor getTempAnchor() 
      return tempAnchor;



      In select_anchor.xml:



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

      <view
      android:id="@+id/anchor_selection_view"
      class="com.decawave.argomanager.ui.view.MyCanvasView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_alignParentTop="true"
      android:layout_centerVertical="true"
      />

      <Button
      android:id="@+id/btn_submit_anchor"
      style="@style/MtrlBorderlessButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_alignParentBottom="true"
      android:layout_margin="5dp"
      android:text="@string/btn_submit_anchor" />


      </RelativeLayout>









      share|improve this question
















      I have a fragment whose layout consists of a custom view (MyCanvasView) and a button. I am trying to access a variable through a getter method in the MyCanvasView class. I am able to access the button to make an OnClickListener, but trying to access the custom view the same way doesn't work. vMapView remains null. How can I get access to the custom view from the fragment that contains it?



      In fragment java file:



      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
      View v = inflater.inflate(R.layout.select_anchor, container, false);

      Button btnSubmitAnchor = (Button) v.findViewById(R.id.btn_submit_anchor);
      MyCanvasView vMapView = (MyCanvasView) v.findViewById(R.id.anchor_selection_view);

      btnSubmitAnchor.setOnClickListener((view) - >

      receivedAnchor = vMapView.getTempAnchor();
      try
      Log.i(TAG, "Received anchor:n" + receivedAnchor.getName());
      catch (Exception e)
      Log.i(TAG, "no anchor was received");

      );

      return v;



      In MyCanvasView.java:



      public Anchor getTempAnchor() 
      return tempAnchor;



      In select_anchor.xml:



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

      <view
      android:id="@+id/anchor_selection_view"
      class="com.decawave.argomanager.ui.view.MyCanvasView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_alignParentTop="true"
      android:layout_centerVertical="true"
      />

      <Button
      android:id="@+id/btn_submit_anchor"
      style="@style/MtrlBorderlessButton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_alignParentBottom="true"
      android:layout_margin="5dp"
      android:text="@string/btn_submit_anchor" />


      </RelativeLayout>






      java android






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 18:17







      the-jfry

















      asked Mar 25 at 23:24









      the-jfrythe-jfry

      13 bronze badges




      13 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Try thus way:



          <com.decawave.argomanager.ui.view.MyCanvasView

          android:id="@+id/anchor_selection_view"

          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_alignParentTop="true"
          android:layout_centerVertical="true"
          />





          share|improve this answer























          • Unfortunately that doesn't solve the issue. vMapView remains null after its initialization in the fragment java file. Does declaring the UI element this way work differently than explicitly declaring the class as I had done?

            – the-jfry
            Mar 26 at 14:27










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347802%2fhow-should-i-get-access-to-a-custom-view-that-is-in-a-fragment-layout%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Try thus way:



          <com.decawave.argomanager.ui.view.MyCanvasView

          android:id="@+id/anchor_selection_view"

          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_alignParentTop="true"
          android:layout_centerVertical="true"
          />





          share|improve this answer























          • Unfortunately that doesn't solve the issue. vMapView remains null after its initialization in the fragment java file. Does declaring the UI element this way work differently than explicitly declaring the class as I had done?

            – the-jfry
            Mar 26 at 14:27















          0














          Try thus way:



          <com.decawave.argomanager.ui.view.MyCanvasView

          android:id="@+id/anchor_selection_view"

          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_alignParentTop="true"
          android:layout_centerVertical="true"
          />





          share|improve this answer























          • Unfortunately that doesn't solve the issue. vMapView remains null after its initialization in the fragment java file. Does declaring the UI element this way work differently than explicitly declaring the class as I had done?

            – the-jfry
            Mar 26 at 14:27













          0












          0








          0







          Try thus way:



          <com.decawave.argomanager.ui.view.MyCanvasView

          android:id="@+id/anchor_selection_view"

          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_alignParentTop="true"
          android:layout_centerVertical="true"
          />





          share|improve this answer













          Try thus way:



          <com.decawave.argomanager.ui.view.MyCanvasView

          android:id="@+id/anchor_selection_view"

          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_alignParentTop="true"
          android:layout_centerVertical="true"
          />






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 23:59









          Siamak FerdosSiamak Ferdos

          1,7981 gold badge19 silver badges45 bronze badges




          1,7981 gold badge19 silver badges45 bronze badges












          • Unfortunately that doesn't solve the issue. vMapView remains null after its initialization in the fragment java file. Does declaring the UI element this way work differently than explicitly declaring the class as I had done?

            – the-jfry
            Mar 26 at 14:27

















          • Unfortunately that doesn't solve the issue. vMapView remains null after its initialization in the fragment java file. Does declaring the UI element this way work differently than explicitly declaring the class as I had done?

            – the-jfry
            Mar 26 at 14:27
















          Unfortunately that doesn't solve the issue. vMapView remains null after its initialization in the fragment java file. Does declaring the UI element this way work differently than explicitly declaring the class as I had done?

          – the-jfry
          Mar 26 at 14:27





          Unfortunately that doesn't solve the issue. vMapView remains null after its initialization in the fragment java file. Does declaring the UI element this way work differently than explicitly declaring the class as I had done?

          – the-jfry
          Mar 26 at 14:27








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347802%2fhow-should-i-get-access-to-a-custom-view-that-is-in-a-fragment-layout%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현