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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:08:35+00:00 2026-06-10T11:08:35+00:00

What I am trying to do is access an ArrayList that is in my

  • 0

What I am trying to do is access an ArrayList that is in my main activity from a customer adapter for a listview.

I have a listview that I am making clickable, which I have done within the customer adapter(where the onclick resides). When the user clicks it they will enter a caption(text) which will update an arraylist(string) in the main activity.

I have read a few other questions about this topic but I’m lost on how to make this work.

I didn’t see the need to post a code snippet because it’s just a basic arraylist(string) and a custom adapter for a listview. If code is needed I can post though. Thanks!

Here part of the adapter code:

public class PhotoAdapter extends ArrayAdapter<Photo> {

    private final ArrayList<Photo> objects;

    public PhotoAdapter(Context context, int textViewResourceId,
            ArrayList<Photo> objects) {
        super(context, textViewResourceId, objects);
        this.objects = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Photo i = objects.get(position);
        View v = convertView;

        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.listview_row, null);
                v.setClickable(true);
                v.setFocusable(true);
        }

Here is come code from the main activity

public ArrayList<Photo> m_photos = new ArrayList<Photo>();
public ArrayList<String> m_photo_captions = new ArrayList<String>();
private PhotoAdapter m_adapter;

this.list1 = (ListView) findViewById(R.id.lstPhotos);
        m_adapter = new PhotoAdapter(this, R.layout.listview_row, m_photos);
        LayoutInflater infalter = getLayoutInflater();
list1.setAdapter(m_adapter);

if (Intent.ACTION_SEND_MULTIPLE.equals(action)
                && intentGallery.hasExtra(Intent.EXTRA_STREAM)) {
            ArrayList<Parcelable> list = intentGallery
                    .getParcelableArrayListExtra(Intent.EXTRA_STREAM);
            for (Parcelable p : list) {
                Uri uri = (Uri) p;
                imagePath = getPath(uri);
                m_photos.add(new Photo(imagePath, ""));
                m_photo_locations.add(imagePath);
                m_photo_captions.add("");
                m_adapter.notifyDataSetChanged();
            }
        }

onclick listener

    list1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
            // Do whatever you want with m_photo_captions here
            Log.v("listview", "listview item clicked");
            appErrorAlert("test", "test");
        }
    });
  • 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-10T11:08:37+00:00Added an answer on June 10, 2026 at 11:08 am

    Now that you have posted your code, I would suggest a different approach than Mohamed A. Karim’s.


    You are trying to set a simple OnClickListener on the entire row in your Adapter but access members of your Activity. Why not just set an OnItemClickListener in your ListView which already has access to the List that you want?

    list1.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // Do whatever you want with m_photo_captions here
        }
    });
    

    Next remove everything that will intercept the touch event before it reaches your ListView. You can also make your getView() a little smaller and faster, like this:

    public class PhotoAdapter extends ArrayAdapter<Photo> {
        LayoutInflater mInflater;
    
        public PhotoAdapter(Context context, int textViewResourceId,
                ArrayList<Photo> objects) {
            super(context, textViewResourceId, objects);
            mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final Photo i = get(position);
            View v = convertView;
    
            if (v == null) {
                v = mInflater.inflate(R.layout.listview_row, null);
                // Initialize your ViewHolder here!
            }
    
            // Update your TextViews, ImageViews, etc here
            ...
        }
    }
    

    Hope that helps!

    • 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 Adapter, and I need to access the
I'm tring to access a function of an instance which is in an arraylist.
Trying to access a Servlet from a button on HTML page //Html Page FORM
Im trying to access the Magento customer session in another part of my website.
I am trying to access information on a website that uses frames. When I
I am trying to access all the data from database listOfFolder table folder and
Hi I'm trying to access a WCF service which returns a JSON Array using
Story I have a select control that represents user access level. I'm looking for
Trying to access a RequiredFieldValidator control that's inside a GridView in the RowCommand event
Im trying to access some variables from the parent in a child mc. Parent

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.