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;
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
add a comment |
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
add a comment |
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
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
java android
edited Mar 26 at 18:17
the-jfry
asked Mar 25 at 23:24
the-jfrythe-jfry
13 bronze badges
13 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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"
/>
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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"
/>
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
add a comment |
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"
/>
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
add a comment |
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"
/>
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"
/>
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
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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