Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:30:50+00:00 2026-06-01T14:30:50+00:00

I’m trying to figure out how to get the value from a method in

  • 0

I’m trying to figure out how to get the value from a method in the Activity class into the Fragment of that Activity.
I have set up three files: AsyncTaskActivity.java, EventsList.java, and ListFragment.java.
AsyncTaskActivity.java has the method getOtakuEvents() that returns a string value.

package com.leobee;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.maps.MapActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class AsyncTasksActivity extends MapActivity implements EventsList{

        LocationManager locationManager;

           String stxtLat ;
           String stxtLong;
           double pLong;
           double pLat;
           String x;

        @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

        // Acquire a reference to the system Location Manager
           locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

           // Define a listener that responds to location updates
           LocationListener locationListener = new LocationListener() {
               public void onLocationChanged(Location location) {
                   pLong=location.getLongitude();
                   pLat=location.getLatitude();
                   stxtLat=Double.toString(pLat);
                   stxtLong=Double.toString(pLong);
                   Toast.makeText(AsyncTasksActivity.this, stxtLong, Toast.LENGTH_SHORT).show();
                   Toast.makeText(AsyncTasksActivity.this, stxtLat, Toast.LENGTH_SHORT).show();


               }

               public void onStatusChanged(String provider, int status, Bundle extras) {}

               public void onProviderEnabled(String provider) {}

               public void onProviderDisabled(String provider) {}

             };


           // Register the listener with the Location Manager to receive location updates
           locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
           DownloadWebPageTask task = new DownloadWebPageTask();

           double numRand = Math.floor(Math.random()*1000);
             String userLat= stxtLat;
            String userLong= stxtLong;
            task.execute(new String[] { "http://www.leobee.com/otakufinder/scripts/geoloco.php?userLat="+userLat+"&userLong="+userLong+"&randNum="+numRand });

        }

        private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
            @Override
            protected String doInBackground(String... urls) {
                String response = "";
                for (String url : urls) {
                    DefaultHttpClient client = new DefaultHttpClient();
                    //HttpGet myGet = new HttpGet("http://foo.com/someservlet?param1=foo&param2=bar");

                    HttpGet httpGet = new HttpGet(url);
                    try {
                        HttpResponse execute = client.execute(httpGet);
                        InputStream content = execute.getEntity().getContent();

                        BufferedReader buffer = new BufferedReader(
                                new InputStreamReader(content));
                        String s = "";
                        while ((s = buffer.readLine()) != null) {
                            response += s;
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                return response;
            }


        @Override
        protected void onPostExecute(String result) {

             x =result;


                Log.v("values",x);

            }

        }


        @Override
        protected boolean isRouteDisplayed() {
            // TODO Auto-generated method stub
            return false;
        }
        @Override
        public String getOtakuEvents() {
            // TODO Auto-generated method stub
            return x;
        }
}

EventsList.java is an interface that helps the classes to know getOtakuEvents() value is available to them.

package com.leobee;

public interface EventsList {

    String getOtakuEvents();

}

Lastly, the fragment has a method that gets the value from the getOtakuEvents() called getStringfromActivity().

 package com.leobee;

    import android.content.Intent;
    import android.content.res.Configuration;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;

    // shows list view of items if fragment is not null this class will also show the item selected form Detailfragment class
    public class ListFragment  extends android.app.ListFragment{
    String events;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            String events =getStringfromActivity();

        }
public String getStringfromActivity() {
        String i;
        i=EventsList.getOtakuEvents();
            return i;
        }



    /*  public String getStringfromActivity() {

        return getActivity().getOtakuEvents();

        }*/


        @Override
        public void onActivityCreated(Bundle savedInstanceState){

            super.onActivityCreated(savedInstanceState);


        String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                "Linux", "OS/2" };

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,values);
            setListAdapter(adapter);

        }

        @Override
        public void onListItemClick(ListView l, View v, int position, long id){

            String item =(String)getListAdapter().getItem(position);
            DetailFragment fragment = (DetailFragment) getFragmentManager().findFragmentById(R.id.detailFragment);


            if (fragment != null && fragment.isInLayout()){

            fragment.setText(item);
            }else{Intent intent = new Intent(getActivity().getApplicationContext(),
                    DetailActivity.class);
            intent.putExtra("value", item);
            startActivity(intent);

            }


        }
        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            Log.e("text","config change detail fragment");
            // Checks the orientation of the screen

        }




    }

I get error: Cannot make a static reference to the non-static method getOtakuEvents() from the type EventsList.
This is confusing because I did not declare static type in getOtakuEvents() or in the fragment.

Alternatively, I also tried this version of the method in the fragment :

  public String getStringfromActivity() {

        return getActivity().getOtakuEvents();

        }

I am getting an error :The method getOtakuEvents() is undefined for the type Activity. This is baffling to me because the method is defined in the parent activity.

Specifically, I need to be able to send the string value from the activity to the fragment. I am trying to do it using an interface or the getActivity method. Can you look over my code and let me know where I’m going wrong and how to fix it? I’ve been at this for the majority of 2 days and can’t seem to figure it out. Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:30:52+00:00Added an answer on June 1, 2026 at 2:30 pm

    You could probably store and retrieve it from SharedPreferences

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.