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

  • Home
  • SEARCH
  • 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 8314183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:44:08+00:00 2026-06-08T20:44:08+00:00

So, I have MainActivity with ArrayList< MyObject>, ListView for display it and EditActivity to

  • 0

So, I have MainActivity with ArrayList< MyObject>, ListView for display it and EditActivity to get UI for editing items. Adapter for ListView extends ArrayAdapter< MyObject>. When user click on item I want to start EditActivity with object for editing. How could I put the object to EditActivity? I have:

    Intent i = new Intent(this, EditActivity.class);
    startActivity(i);

how could I get the object in EditActivity?
Of course, I could declare ArrayList< MyObject> as static and put index of the item with:

    Intent i = new Intent(this, EditActivity.class);
    i.putExtra("index", iItemIdex);
    startActivity(i);

and then, in EditActivity, get it like:

    int iIndex = getIntent().getExtras().getInt("index");
    MyObject o = MainActivity.MyArray.get(iIndex);

but I guess that is not best decision 🙂

  • 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-08T20:44:10+00:00Added an answer on June 8, 2026 at 8:44 pm

    You don’t have to declare your List static. Here is the code you should have to get it to work (one possibility) :

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        MyObjectClass obj = (MyObjectClass) arg0.getAdapter().getItem(arg2);
        Intent intent = new Intent(this, EditActivity.class);
        intent.putExtra("myKey", obj);
        startActivity(intent);
    }
    

    This way there is no useless static variables, and you are using the method the way it has been made for. One of the easiest and cleanest solution IMO.
    Be carefull, to use this method, your have to redefine the getItem(int) method in your custom ArrayAdapter. You should do this :

    @Override
    public MyObjectClass getItem(int position) {
        return this.myList.get(position);
    }
    

    EDIT : Then if you want to be able to remove items, I think you should put the whole list containing your objects in the intent (don’t declare it static). Then just call add()/remove() methods, and when you want to update UI to show the modifed list, just call notifyDataSetChanged() on your custom ArrayAdapter, for example when returning in MainActivity :

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        yourListAdater.notifyDataSetChanged();
        /* Assuming you have a reference pointing to your adapter in your MainActivity, if you don't just do: ((MyCustomAdapterClass) myListView.getAdapter()).notifyDataSetChanged(); */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview with a custom array adapter: public class SmsMessageAdapter extends ArrayAdapter<ContactMessage>
I have 2 tabs, named : Tab1, Tab2 class MainActivity extends TabActivity. MainActivity.java public
I have 3 Acivity based application, It's work flow like this MainActivity ListView and
I have a MainActivity class with an Add Item button and a listview and
in my app, I have a MainActivity that consist of many items that can
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
I have an application project with source files: androidsrc/MainActivity.java androidsrc/ClientSession.java I get this error
I have an activity ( MainActivity.java ) in which content view is like this
My Application has 3 activities (MainActivity,SampleActivity,TempActivity) and Application have to start from MainActivity because
I have an activity, I'll call it mainactivity for now. And I want to

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.