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. input method apk.

Hi, everyone,

Who can give me a input method application which can replace QWERTY
keypad and do not need a HVGA screen (that can also fit VGA / WQVGA /
QVGA)?

Thanks.

(I have post this message twice, but I did not see the posted message,
where it is?)

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

2. Customize search bar

I am developing an application that needs to extend a bit the
functionality of the android search bar. Basically I need to add a
checkbox below the editbox search text to allow performing a search
backwards/forward in a document. Currently my activity is searchable
and shows the native SearchDialog every time the user clicks on a
specific menu option. However I don't see the way to customize the
native search dialog at all.

I'd like to keep using the search UI in my activity with these
extended search options but I'm afraid all have to desist doing that.
Instead I imagine the only alternative I have got is to design my own
search bar and and stop using the native search functionality.

So, my question would be "is the search UI customizable at all"?

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

3. clickable items in a ListView with a context menu?

4. (WAY OT!) iPhone is everything :))))

5. Video call support at Cupcake version.

6. http proxy and chunked encoding with emulator

7. Why drawing in View.onDraw not take effect, but does in ViewGroup.dispatchDraw