java - ListView only displaying first item in arraylist -


list view displaying first item in data. how make display data in array list. think because using the same key in map bur how change , make appear. appreciated.

package menu.saryal.example.com.menu;  import android.content.intent; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.adapterview; import android.widget.arrayadapter; import android.widget.listview;  import java.util.arraylist;   /**  * placeholder fragment containing simple view.  */ public class itemorderedfragment extends fragment {      private arrayadapter<string> itemtitle;     public final static string  extra_text = "menu.saryal.example.com.menu";      public itemorderedfragment getthisitemorderedfragment() {         return thisitemorderedfragment;     }      itemorderedfragment thisitemorderedfragment = this;      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_item_ordered, container, false);          final menudbhelper dbhandler = new menudbhelper(this.getactivity());         arraylist<menudescription> data = dbhandler.readdata();          // reference listview, , attach adapter it.         listview listview = (listview) rootview.findviewbyid(r.id.fragment_item_ordered_list_view);         arraylist<hashmap<string, string>> albumslist;         albumslist = new arraylist<hashmap<string, string>>();         hashmap<string, string> map = new hashmap<string, string>();          // adding each child node hashmap key => value         for(menudescription x:data){             map.put("title", x.gettitle());             map.put("description", x.getdescription());         }         // adding hashlist arraylist         albumslist.add(map);          listadapter adapter = new simpleadapter(                 this.getactivity(),                 albumslist,                 r.layout.list_item_with_image,                 new string[] { "title", "description"},                 new int[] {r.id.list_item_with_image_text_view, r.id.recepit_cost_text_view });         if (data.size()>0){             listview.setadapter(adapter);         }          listview.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> adapterview, view view, int position, long l) {                 string title = itemtitle.getitem(position);                 menudescription item = dbhandler.findbytitle(title);                 string cost_string = "" + item.getcost();                 string totalcost_string = "" + item.totalcost;                 string totalorder_string = "" + item.gettotalorder();                 string[] transfer_data = {item.gettitle(),item.getdescription(),cost_string,totalcost_string,totalorder_string,item.getimage()};                 intent intent = new intent(getactivity(), editdetailpage.class);                 intent.putextra(extra_text, transfer_data);                 startactivity(intent);             }         });         dbhandler.close();         return rootview;     } } 

that's because adding 1 hashmap arraylist.

arraylist<hashmap<string, string>> albumslist = new arraylist<hashmap<string, string>>();  for(menudescription x:data){     //prepare new hashmap     hashmap<string, string> map = new hashmap<string, string>();     map.put("title", x.gettitle());     map.put("description", x.getdescription());     //add hashmap arraylist     albumslist.add(map); } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -