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.


@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

MyArrayAdapter myAdapter = new MyArrayAdapter(getApplicationContext(), R.layout.appsview_item, List, new RefreshInterface () {
                 
                  @Override
                  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

intr.refresh();


}
}

3 comments:

  1. We stumbled over here different web address and
    thought I may as well check things out. I like what I see so now i am following you.
    Look forward to looking at your web page again.

    Here is my homepage: Bathroom Sinks
    my site - pages.rediff.com

    ReplyDelete
  2. Thank уou for the аuspicious writeup. It in faсt was a amusement account it.

    Look advanced to mοгe aԁdeԁ agreeable frοm yοu!
    By the way, how сould we communicаte?

    Feel free to surf tο my blοg post; keyword

    ReplyDelete
  3. Thankfulness to my father who shared with me about this blog, this blog is truly amazing.สล็อตออนไลน์

    ReplyDelete

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...