0

I want to modify the visibility of an ImageView which is located in the layout of an activity, from a fragment which is loaded in a container inside parent activity's layout.

In a parent activity class I have this method:

public void enableAddEvvOkBtn(boolean mHide, Activity mActivity) {
    view = getView();
    if(mHide) btnAddEvVOk.setVisibility(View.VISIBLE);
    else btnAddEvVOk.setVisibility(View.GONE);
}

and in the fragment I am calling the method:

tabSketch.enableAddEvvOkBtn(true, getActivity());

where tabSketch is an instance of the parent activity.

However this is not working, I think it must be something related to the context how can I make this work?

Jhonycage
  • 759
  • 3
  • 16
  • 36

1 Answers1

0

You can use this code to make Visible/Gone more simple

btnAddEvVOk.setVisibility(btnAddEvVOk.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);

This makes the Button visible if=gone and gone if= visible

ORY
  • 393
  • 1
  • 4
  • 11
  • keeps stopping, this instruction is inside the method right? – Jhonycage Apr 23 '17 at 08:27
  • 'public void enableAddEvvOkBtn(boolean mHide, Activity mActivity) { view = getView(); if(mHide) btnAddEvVOk.setVisibility(View.VISIBLE); else btnAddEvVOk.setVisibility(View.GONE); }' instead of this you can use 'public void setButtonVisibility(){ btnAddEvVOk.setVisibility(btnAddEvVOk.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); } – ORY Apr 23 '17 at 08:30