android - How to set 5 different Strings into one Item of ListView? -


i trying set 5 strings, airport_finish, date_finish, time_finish, persons_finish, address_finish & flightnr_finish, in 1 item of listview associated class demandfragment extends fragment.

will possible? how do it?

right strings in separate items.

finishpostfragment:

@override public boolean onoptionsitemselected(menuitem item) {     switch (item.getitemid()) {         case r.id.add_post_finish:             // user chose "favorite" action, mark current item             // favorite...             final fragmentmanager fm = getactivity().getfragmentmanager();             final fragment fragment = new demandfragment();              // put strings listview in demandfragment             parseobject post = new parseobject("posts");              post.put("airport", airport_finish.gettext().tostring());             post.put("date", date_finish.gettext().tostring());             post.put("time", time_finish.gettext().tostring());             post.put("persons", persons_finish.gettext().tostring());             post.put("address", address_finish.gettext().tostring());             post.put("flightnr", flightnr_finish.gettext().tostring());              post.saveinbackground(new savecallback() {                 @override                 public void done(parseexception e) {                     airport_finish.settext("");                     date_finish.settext("");                     time_finish.settext("");                     persons_finish.settext("");                     address_finish.settext("");                     flightnr_finish.settext("");                      parsequery<parseobject> query = parsequery.getquery("posts");                     query.findinbackground(new findcallback<parseobject>() {                         public void done(list<parseobject> scorelist, parseexception e) {                             if (e == null) {                                 arraylist arraypost = new arraylist<string>();                                  (parseobject j : scorelist) {                                      arraypost.add(j.getstring("airport"));                                     arraypost.add(j.getstring("date"));                                     arraypost.add(j.getstring("time"));                                     arraypost.add(j.getstring("persons"));                                     arraypost.add(j.getstring("address"));                                     arraypost.add(j.getstring("flightnr"));                                 }                                  bundle bundle = new bundle();                                 bundle.putstringarraylist("listpost", arraypost);                                 fragment.setarguments(bundle);                                 fm.begintransaction().replace(r.id.content_main, fragment).commit();                              } else {                                 // error                             }                         }                     });                 }             });              return true; 

demandfragment:

    public class demandfragment extends fragment {      listview lv;      arraylist yourlist;     arrayadapter adapter;      @nullable     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_demand, container, false);          if(rootview != null){             lv = (listview) rootview.findviewbyid(r.id.listdemand);              arraylist<string> arraypost = getarguments().getstringarraylist("listpost");             log.d("arraylist", "arraypost");              arrayadapter adapter = new arrayadapter(getactivity(), android.r.layout.simple_list_item_1, arraypost);              lv.setadapter(adapter);              lv.setonitemclicklistener(new adapterview.onitemclicklistener() {                 @override                 public void onitemclick(adapterview<?> parent, view view, int position, long id) {                     // clicked on item show post                  }             });         }          return rootview;     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          sethasoptionsmenu(true);      }  } 

what want create custom item listview.

and can make custom row how ever want xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >  <textview android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="header"/>  <textview      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/text"/>   </linearlayout> 

which that:

enter image description here

in case have 5 textviews...

here how it: https://stackoverflow.com/a/15832564/3180983

you need extend baseadapter , override methods in order make work.


Comments