How can I call methods in Activity from an event listener of a custom Adapter?

by Daniel Yen » Thu, 16 Apr 2009 00:56:24 GMT


Sponsored Links
 Hi everyone,

I have created a ListView and a custom Adapter with ImageButton widget
in each row. I set the ImageButton OnClick Listener in getView method
to trigger each ImageButton's OnClick event of each ListView row.
Everything goes well, but I have no idea how to call Activity methods
from ImageButtons' OnClickListener handler.

I initial my ListView as following code

in MyActivity class:

protected void onCreate(Bundle savedInstanceState) {
          MyListAdapter myListAdapter = new MyListAdapter
( MyActivity.this,
                                R.layout.list_row,
                                myList );
          myListView.setAdapter(myListAdapter);
}

in MyListAdapter  class:

public View getView(int position, View convertView, ViewGroup parent)
{
  LayoutInflater inflate = LayoutInflater.from( context );
  View v = inflate.inflate( rowResID, parent, false);
  ImageButton button1 = (ImageButton)v.findViewById( R.id.button1 );

   button1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {

                     //How to call MyActivity class methods from
here??

              }
    });
}

Thank you for your kindly help in advance.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. ItemizedOverlay animations on a MapView

Hi,

How do I make ItemizedOverlay animations on a MapView.

After some searching it seems AnimationDrawable is the right way to
go, but the following code only show the first frame, what else I need
to do?

AnimationDrawable animation =
(AnimationDrawable)getResources().getDrawable(R.anim.animation);
ItemizedOverlay overlay = new ItemizedOverlay(this, animation);
...
...
animation.start();


Thanks,

Hongbo

-- 

2. Re-installing an updated .apk file....

Hi

How can i reinstall the existing apk file with the new updated apk
file on the mobile phone, and similarly i also want to know that if
there is an update on the apk file that i have already installed from
Android Market, do i get any message to my mobile, saying that i have
an update on my apk file which i have to reinstall on my mobile?

Thanks & Regards,
Sai Kiran V.

--

3. Default Map Not Showing Up During Tutorial

4. onClick mouse position

5. Usage of TextView. Append and setText.

6. Filtering ListViews powered by SimpleCursor Adapter

7. launch app with private URL schema from browser