简体   繁体   中英

Android how to use control from other XML file

I'm using Android studio. I have activity_main.xml and MainActivity.java , secondactivity.xml and SecondActivity.java for it.

I have a button control in activity_main.java .

I want to use that button.click event from SecondActivity.java (not from MainActivity.java) .

How can I use control of XML files other than that's particular JAVA file. I'm trying,

  Button but = (Button)  FindViewById(R.Layout.activity_main)

In SecondActivity.java file but I got failed, where am I wrong. Please help.

see in FindViewById you pass layout. activity file and you cast in button object that is not possible you try to pass button id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM