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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:46:25+00:00 2026-05-23T15:46:25+00:00

My activity has a ListView that has a custom ArrayAdapter. On my ArrayAdapter i

  • 0

My activity has a ListView that has a custom ArrayAdapter.
On my ArrayAdapter i have an image, a bunch of textboxes and a button.

On the getView of the adapter i get my button and set setOnClickListener. From the click listener i can get the index of the clicked item.

Now my problem is that i want to propagate that information to my main activity, where i want to handle my button click.
I can save the index information in a static var, but i still don’t know how to fire an event in my activity.

How do i do that?

I’m 6 days new to Android so, thanks
iggy

Code:

My Activity:

public class MyClass extends Activity{
...
    public void onCreate(Bundle savedInstanceState) {
    ...
    myListView = (ListView)findViewById(R.id.lvxml);
    myList = new MyCustomArrayAdapter(this, myAnotherClassObject);
    myListView .setAdapter(myList);
    ...
    }
}

Now in my Adapter

public class MyCustomArrayAdapter extends ArrayAdapter<myAnotherClass> {
...
....
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

         Button b = (Button)convertView.findViewById(R.id.myButtonInListView);
         b.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 doStuff;
             }
     });
    }
}

I need to somehow fire a buttonclick from my main activity, but without loosing the possibility to read the index clicked in the list view.

  • 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-23T15:46:25+00:00Added an answer on May 23, 2026 at 3:46 pm

    So I’ve solved it somehow. It’s probably not the way to do it but it works.

    I save my activity in a static var.

    Button b = (Button)convertView.findViewById(R.id.myButtonInListView);
    b.setTag(position);
    b.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 int i = (Integer) v.getTag();
                 myStaticVarRep.myActivity.myMethod(i);
             }
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity that has a TabHost containing a set of TabSpecs each
I currently have a ListView with a custom adapter that gets information describing the
I have an activity with ListView that has: android:theme=@android:style/Theme.Dialog in Manifest. When I open
I have an android-app with a listview in an activity. The listview has, if
I have an activity that has two tabs and a list view in each.
How can a have a ListView that has different amount of rows? Instead of
I have a ListView that uses SimpleAdapter, each row has 2 TextViews, and I
My launch activity extends ListActivity and uses a layout that has a listview and
I have an activity which pops up a custom dialog. On that dialog I
I have created an application for Android that has an activity that has a

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.