• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing one class file from a fragment or a MainActivity file.  RSS feed

 
Joe Vogler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have several different PopupWindows that i want to access from the same fragment. I would like for each PopupWindow to be it's own java file. Here is trimmed down code from an example showPopup.java file,
showPopup.java

and here is the code from a fragment that will be calling the popup,
Tab3Fragment.java
QUESTION: How do I configure inheritance to allow showPopup() class to reside in it's own Java file and be called from another class (file)? I've reviewed several hours of online resources as well as my reference books with no productive illumination. I've tried a number of possible implementations and extensions such as "public class showPopup extends Activity implements View.OnClickListener{...", and "public class showPopup extends Window {..." with no luck. What am I missing here? Thanks.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Vogler wrote:I would like for each PopupWindow to be it's own java file.


Class sources are in java source files. A class can have several instances sharing the same type (class).
 
Joe Vogler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point Ivan.
Reviewing the provided code, what do I need to change to access showPopup.java from Tab3Fragment.java? Thanks.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to create a new instance of the class showPopup through its default (no-argumant) constructor:

 
Joe Vogler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the error message shown in the Android Build Toolset,
"The method showPopup2() is undefined for the type Tab3Fragment"
when this,

is posted in Tab3Fragment.java, and onClick() is modified as...

Thanks Ivan, but I'm still missing something-
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

refers to the method called showPopup2. This creates a new instance of the class showPopup2:


There seems to be a confusion about classes, objects (instances) and methods.
 
Joe Vogler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your patience in explaining this.
This is what I have...

Isn't this what you are describing that should work? Thanks again.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message is pretty clear: you are trying to invoke a method which does not exist.

The remedy is either to provide the method or not to invoke it.
 
Joe Vogler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the suggestions. Here is the amended code, showPopup.java


and Tab3Fragment.java


Question: How do I inherit the methods in showPopup.java so that when showPopup2() is initiated in Tab3Fragment.java, a PopupWindow is created? Thanks again for your help.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!