Sunday, February 17, 2013

Android Activity method from the adapter class

Android Activity method from the adapter class

Below the example for how to call activity method from adapter class.

Some time I try to call activity method from base adapter or adapter class but I unable to call this method or I am getting some error. So finally I got the solution .
Below the code
Create Interface Class 

public interface RefreshInterface {
public void refresh();

Then implement this interface to your activity class.

    public void onCreate(Bundle savedInstanceState) {

MyArrayAdapter myAdapter = new MyArrayAdapter(getApplicationContext(), R.layout.appsview_item, List, new RefreshInterface () {
                  public void refresh() {
          //do something here
Call activity method from adapter class

public class MyArrayAdapterextends ArrayAdapter<Structure> {

RefreshInterface intr;
public MyArrayAdapter(Context context, int textViewResourceId,
                  List<App> objects, RefreshInterface refreshInt) {
            super(context, textViewResourceId, objects);
            intr = refreshInt;

public View getView(final int position, View appView, ViewGroup parent) {

//this is your activity method



Check out this may be help you

Related Posts Plugin for WordPress, Blogger...