Results 1 to 2 of 2
  1. #1
    ShiZhi is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default Passing current class as a parameter problem

    I want to pass the class I am in as a parameter for a method from another class. Normally, I would just use
    Java Code:
    , but it doesn't work because the method is within an onTouchListener, so when I try to pass it, I get an error message saying that it is not compatible because it is representative of new View.onTouchListener rather than the class that I am wanting to pass. Here is my code:

    Java Code:
    //Here I am trying to get an integer using the countChar method from my Functions class.  This function requires me to pass the class MainActivity, which I am able to successfully achieve by using "this".
    Functions funct = new Functions();
    SldList.setMax(funct.countChar(this, "symtitles.sva", "§") - 1);
    		SldList.setOnTouchListener(new View.OnTouchListener() {		
    			public boolean onTouch(View v, MotionEvent event) {
    				Settings s = new Settings();
    				 int savesplit = s.SldGroupBy.getProgress();
    //Here, however, within the onTouchListener I am unable to use "this" to pass the class as a parameter for the method getDataSplit from the Functions class.
    				 String title = funct.getDataSplit(this, "symtitles.sva", (SldList.getProgress() + 1)).replace("‰", " ");
    				return false;
    I've tried simply creating an object of the class like so:
    Java Code:
    MainActivity main = new MainActivity()
    but for reasons that are probably obvious to you this did not work (it would seem you cant create an object of your a class within that class itself). Anyway, I would really appreciate some help, thanks!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Passing current class as a parameter problem

    Java Code:
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Passing a class's object as parameter to a method...
    By darshanaprasad in forum New To Java
    Replies: 4
    Last Post: 12-15-2012, 10:07 PM
  2. passing date into parameter
    By tike in forum New To Java
    Replies: 5
    Last Post: 12-08-2011, 05:30 PM
  3. Passing final parameter from a class
    By ianyappy in forum New To Java
    Replies: 8
    Last Post: 12-02-2010, 07:06 PM
  4. passing parameter to a thread
    By adammyth in forum Threads and Synchronization
    Replies: 1
    Last Post: 01-02-2010, 07:58 PM
  5. passing a parameter
    By aarthi2learn in forum AWT / Swing
    Replies: 4
    Last Post: 12-22-2008, 05:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts