-1

I want to call this function from another class.

How do I call it from another classs?.

It¡ss not possible to achieve using normal function call, as I am not getting access to the view of the main function.

 public class Blank  extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call);
        Button buttonHangup = (Button) findViewById(R.id.buttonHangup);
        Button buttonHanup2=(Button) findViewById(R.id.buttonHangup2);
        }
 
    public void bringBack(){

        Button buttonHangup = (Button) findViewById(R.id.buttonHangup);
        Button buttonHanup2=(Button) findViewById(R.id.buttonHangup2);
        buttonHangup.setText("Hangup no ok ");
        buttonHanup2.setVisibility(View.VISIBLE);

    }


}

how can i call this bringback function from another class as its not allowed to call using normal method call ...as i dont get access to button view from another class eg

 Blank bl =new Blank();
     bl.bringback()

it wont work as i dont get access to button view ..

James
  • 318
  • 1
  • 10
  • Hi @James, please, add more details from which classes do you want to call this method,where is this method, etc.. Paste the need of the other files, so we can help you – Shudy Oct 26 '21 at 11:04
  • hi @Shudy i have updated question with code. my main issue is i dont get access to view from method called outside from its class – James Oct 26 '21 at 11:17
  • Follow this Link : https://stackoverflow.com/a/34951687/11138845 – S_i_l_e_n_t C_o_d_e_r Oct 26 '21 at 11:25

1 Answers1

0

you can't call a graphical interface that way because blank extends from activity so you need to have the interaction with the layout.

What you could do is create a fragment with your own layout and embed it in different activities.

You could use a fragment that contains a button and this load it in your activities, for this you must create a framelayout within the layout of your activity where your fragment will be visible.

activity layout

enter image description here

Now you must create a fragment that contains a button

enter image description here

Now you must load this fragment in your activity (if at some point you don't need it anymore you can empty the framelayout or make it invisible)

enter image description here

In this way you can use the same button in different activities