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. <WTMintaTulung> Browser saya kenapa ya?

Udah dari dulu nih kasusnya.
Jadi setiap pake wifi, semua browser bisa dipake (Skyfire, Dolphin,
Opera, Browser default). Tapi kalo udah pake paket data yang bisa
dipake cuman Opera saja.
Ada yang tahu caranya biar semuanya normal pas paket data diaktifkan?
Saya pake Indosat
Gara2 ini nih sampe sekarang belum langganan paket data (selain ngga
punya duid :P)

-- 
"Indonesian Android Community [id-android]" 

2. ActivityNotFoundException and txt files

I am trying to open at .txt file in the standard file editor, I tryed
this code but all I get is an ActivityNotFoundException

                File root = Environment.getExternalStorageDirectory();
                File f = new File(root, "/Android/data/HKKalender/
stdtekster.txt");

                try {
                Intent intent = new Intent(Intent.ACTION_EDIT);
                intent.setDataAndType(Uri.fromFile(f), "text/plain");
                startActivity(intent);
                } catch (Exception e) { }

-- 

3. Update Survey Resul

4. Need help - Android mkdir("/sdcard/") fails on Frayo

5. Jafar the qwerty man!

6. OpenGL ES Java binding not supported on Nexus One + Android 2.2?

7. progressive video play over https