android - footer view not displayed in listview (Custom adapter) -


footer view not displayed @ end of listview . pleas tell me going wrong .the code footerview :

footerview = ((layoutinflater)getbasecontext()                 .getsystemservice(context.layout_inflater_service)).inflate(                 r.layout.listfooter, null, false);         list.addfooterview(footerview);          footerview.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub              }          }); 

entire code :

public class customizedlistview extends activity {     // static variables     static final string url = "https://itunes.apple.com/us/rss/topalbums/limit=20/json";     // xml node keys     static final string key_song = "song"; // parent node     static final string key_id = "id";     static final string key_title = "title";     static final string key_artist = "artist";     static final string key_duration = "duration";     static final string key_thumb_url = "thumb_url";      static listview list;     static lazyadapter adapter;      hashmap<string, string> map;      public static  string message_receiver_str;      public static int deleteposition;     public static arraylist<hashmap<string, string>> songslist;      view footerview ;       @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);           songslist = new arraylist<hashmap<string, string>>();          jsonobject json = jsonfunctions.getjsonfromurl(url);           try {             jsonobject arr2 = json.getjsonobject("feed");             jsonarray arr = arr2.getjsonarray("entry");              (int = 0; < arr.length(); i++) {                 jsonobject e1 = arr.getjsonobject(i);                  jsonarray arr3 = e1.getjsonarray("im:image");                  jsonobject arr8 = e1.getjsonobject("im:name");                  jsonobject arr10 = e1.getjsonobject("im:artist");                      jsonobject e12 = arr3.getjsonobject(0);              // creating new hashmap              map = new hashmap<string, string>();              map.put(key_thumb_url,  e12.getstring("label"));              map.put(key_artist, arr8.getstring("label"));             map.put(key_title, arr10.getstring("label"));             // adding hashlist arraylist             songslist.add(map);             }          } catch (jsonexception e) {             // log.e("log_tag", "error parsing data "+e.tostring());             toast.maketext(getbasecontext(),                     "network communication error!", 5).show();         }           list=(listview)findviewbyid(r.id.list);          // getting adapter passing xml data arraylist         adapter=new lazyadapter(this, songslist);                 list.setadapter(adapter);          // click event single list row         list.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> parent, view view,                      int position, long id) {                                  @suppresswarnings("unchecked")                                 hashmap<string, string> o= (hashmap<string, string>) list.getitematposition(position);                             //   toast.maketext(customizedlistview.this, "id '" + o.get("title") + "' clicked.", toast.length_short).show();                                   deleteposition=position;                              message_receiver_str= o.get("title");                              intent ii= new intent(getbasecontext(),openedmsg.class);                                  startactivity(ii);              }         });                   footerview = ((layoutinflater)getbasecontext()                 .getsystemservice(context.layout_inflater_service)).inflate(                 r.layout.listfooter, null, false);         list.addfooterview(footerview);          footerview.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub              }          });      }    } 

lazyadapter.java

public class lazyadapter extends baseadapter {      private activity activity;     private arraylist<hashmap<string, string>> data=new arraylist<hashmap<string, string>>();     private static layoutinflater inflater=null;     public imageloader imageloader;       public static hashmap<string, string> song;      public lazyadapter(activity a, arraylist<hashmap<string, string>> d) {         activity = a;         data=d;         inflater = (layoutinflater)activity.getsystemservice(context.layout_inflater_service);         imageloader=new imageloader(activity.getapplicationcontext());     }      public int getcount() {         return data.size();     }      public object getitem(int position) {          return data.get(position);     }      public long getitemid(int position) {         return position;     }      public view getview(int position, view convertview, viewgroup parent) {         view vi=convertview;         if(convertview==null)             vi = inflater.inflate(r.layout.list_row, null);          textview title = (textview)vi.findviewbyid(r.id.title); // title         textview artist = (textview)vi.findviewbyid(r.id.artist); // artist name         textview duration = (textview)vi.findviewbyid(r.id.duration); // duration         imageview thumb_image=(imageview)vi.findviewbyid(r.id.list_image); // thumb image           song = new hashmap<string, string>();         song = data.get(position);          // setting values in listview         title.settext(song.get(customizedlistview.key_title));         artist.settext(song.get(customizedlistview.key_artist));         duration.settext(song.get(customizedlistview.key_duration));         imageloader.displayimage(song.get(customizedlistview.key_thumb_url), thumb_image);         return vi;     } } 

listfooter.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="horizontal"     android:layout_width="fill_parent"     android:gravity="center_horizontal"     android:padding="13dp"     android:layout_height="fill_parent">          <textview         android:id="@id/android:empty"         android:layout_width="wrap_content"         android:layout_height="fill_parent"         android:gravity="center"         android:padding="15dp"         android:text="tap load"         android:textcolor="@android:color/darker_gray"/>  </linearlayout> 

you must call addfooterview() before call setadapter() on listview. same applies addheaderview().


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -