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 7702739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:17:45+00:00 2026-05-31T23:17:45+00:00

I have a problem that is a little hard to explain. I am building

  • 0

I have a problem that is a little hard to explain. I am building an android application for trip planning. I have a main activity that contains the map item and some other buttons and an AsyncTask class where the communication with the server is done and the path is displayed on the map. I am trying to make it work offline by saving the response from the server in sqllite database.

I have an Activity called MainActivity. There, I have a method for menu items

public boolean onOptionsItemSelected(final MenuItem pItem) {        
    switch (pItem.getItemId()) {
    case R.id.recent_trips:
            startActivity(new Intent(this, recentTripsActivity.class));
            break;
    default:
             break;
        }

        return false;
    }
}

Here is the current method for calling the AsyncTask class

btnPlanTrip.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
      tripReq = new TripRequest(MainActivity.this,activityHandler,db);
    tripReq.execute(request);
    }
     });
}

When I click on the recent_trips from the menu button, recentTripsActivity opens. Basically, in this class I retrieve some data from mysqllite database and present it on a listView through an adapter. There, I have a method view.setOnClickListener in which when a list item is clicked I take a certain value (res=listItem.getofflineResult();). I would like to use that value on Main Activity (see below for more details).
Here is the code.

public class recentTripsActivity extends Activity implements Serializable {
    private ImageButton stopSearch;
    private AutoCompleteTextView searchField;
    SQLiteDatabase db;
    OfflineTripRequest tripReq;
    String res;
    //db = openOrCreateDatabase("AndroidDatabase.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);


     private ListView listview;
     private ArrayList mListItem;
     ItemBO listItem;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.recent_trips); 

            //open database connection
            db = openOrCreateDatabase("AndroidDatabase.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
            int i=0;
            String [] str={"id","description","offlineResult"};
            listview = (ListView) findViewById(R.id.lview_trips);

            mListItem = new ArrayList<ItemBO>();

            Cursor cursor = db.query("tbl_offlinePathResult",str, null, null, null, null, null);

            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                i++;
                ItemBO listItem = new ItemBO(i,cursor.getString(1),cursor.getString(2));
                mListItem.add(listItem);
                cursor.moveToNext();
                if(i==10){
                    break;
                }
            }
            // Make sure to close the cursor
            cursor.close();
            i++;

            listview.setAdapter(new ListAdapter(recentTripsActivity.this, R.id.lview_trips,mListItem));
            db.close();
    }


//***ListAdapter***
 class ListAdapter extends ArrayAdapter { //--CloneChangeRequired
    private ArrayList mList; //--CloneChangeRequired
    private Context mContext;

    @SuppressWarnings("unchecked")
    public ListAdapter(Context context, int textViewResourceId,
            ArrayList list) { //--CloneChangeRequired
        super(context, textViewResourceId, list);
        this.mList = list;
        this.mContext = context;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        try {
            if (view == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = vi.inflate(R.layout.list_item_saved_paths, null); //--CloneChangeRequired(list_item)
            }
            final ItemBO listItem = (ItemBO) mList.get(position); //--CloneChangeRequired
            if (listItem != null) {
                // setting list_item views
                ((TextView) view.findViewById(R.id.tv_name))
                        .setText(listItem.getDescription());

                view.setOnClickListener(new OnClickListener() {
                    public void onClick(View arg0) { //--clickOnListItem
                         res=listItem.getofflineResult(); 

                    }
                });
            }
        } catch (Exception e) {
            Log.i(recentTripsActivity.ListAdapter.class.toString(), e.getMessage());
        }
        return view;
    }
 }
}

I would like to pass the data mentioned above(res=listItem.getofflineResult() to MainActivity. After doing that I would like to call an AsyncTask class and pass that data to that class. How can I do all this by clicking on the listItem? As I said before the map is on MainActivity but the click will happen from a different Activity.
I hope I made my self clear enough, If you have any questions please ask me

  • 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-05-31T23:17:47+00:00Added an answer on May 31, 2026 at 11:17 pm

    First, you need to override onListItemClick in your list. You will then need to put the needed information into a bundle and end the activity. This bundle gets “returned” to the calling activity in that activity’s onActivityReuslt method (which you will need to override). See:

    Passing Data Between Activities

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

Sidebar

Related Questions

i have created little search method. The problem that its hard to read it
I have a little newbie problem that I cannot figure out, I am having
I have this little problem, that I cannot figure out which arguments to pass
I have a little problem with autoconf, I know that you can use configure.ac
In a couple of scripts that I use I have problem that is intermittent.
I have a problem that confuses my users, being that although an item is
I have the problem that an specific step in Ant can only be executed
I have a problem that I would like have solved via a SQL query.
I have a problem that I feel is best implimented in a stand alone
I have a problem that seems like its a result of a deadlock-situation. Whe

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.