android - Checkbox in ListView with JSON object -


i getting confused codes. trying have favorite button in each item of listview , using checkbox. when user checks checkbox, want viewable on page can see checked item (which listview). have no submit/save button checked item automatically save/display page. items in listview database , many sources provides solutions static data/arraylist. however, data jsonobject , not familiar java @ all.

i have no idea went wrong:

streamnotices.java

    package com.example.smartinfo2;       public class streamnotices extends listactivity{       private menuitem menuitem;     private listview listview;      // progress dialog     private progressdialog pdialog;      ...      // json ids:     private static final string tag_notice = "notice";     private static final string tag_announcementid = "announcementid";     private static final string tag_deptno = "deptno";     private static final string tag_moduleid = "moduleid";     private static final string tag_subject = "subject";      private static final string tag_message = "message";     private static final string tag_posted_date = "posted_date";     private static final string tag_success = "success";      private jsonarray mcomments = null;      private arraylist<hashmap<string, string>> mcommentlist;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.announcements);          ..      }            public void onclick(view v) {              listview list = getlistview();                 list.setchoicemode(listview.choice_mode_multiple);              int pos = list.getcheckeditemposition(); //list being listview defined              //look checked checkbox in particular position              checkbox checkbox = (checkbox)findviewbyid(pos);              if (checkbox.ischecked()) {                      intent = new intent(this, resultactivity.class);                     startactivity(a);              }          }       @override       public boolean oncreateoptionsmenu(menu menu) {         menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.main, menu);         return true;       }       @override     public boolean onoptionsitemselected(menuitem item) {         // handle presses on action bar items         switch (item.getitemid()) {             case r.id.action_refresh:                 loadcomments notice = new loadcomments();                 notice.execute();                 return true;             default:                 return super.onoptionsitemselected(item);         }     }       @override      protected void onresume() {      // todo auto-generated method stub      super.onresume();       new loadcomments().execute();      }        /**      * retrieves recent post data server.      */     public void updatejsondata() { ]         mcommentlist = new arraylist<hashmap<string, string>>(); ]         jsonparser jparser = new jsonparser();]         jsonobject json = jparser.getjsonfromurl(read_comments_url);          // when parsing json stuff, should         // try catch exceptions:         try { ]             mcomments = json.getjsonarray(tag_notice);              // looping through posts according json object returned             (int = 0; < mcomments.length(); i++) {                 jsonobject c = mcomments.getjsonobject(i);                  // gets content of each tag                         string id = c.getstring(tag_announcementid);                         string date = c.getstring(tag_posted_date);                         string name = c.getstring(tag_deptno);                         string module = c.getstring(tag_moduleid);                         string title = c.getstring(tag_subject);                         string content = c.getstring(tag_message);                 // creating new hashmap                 hashmap<string, string> map = new hashmap<string, string>();                          map.put(tag_announcementid, id);                         map.put(tag_posted_date, date);                         map.put(tag_deptno, name);                         map.put(tag_moduleid, module);                         map.put(tag_subject, title);                         map.put(tag_message, content);                  // adding hashlist arraylist                 mcommentlist.add(map); ]             }          } catch (jsonexception e) {             e.printstacktrace();         }     }      /**      * inserts parsed data listview.      */     private void updatelist() {         ]         listadapter adapter = new simpleadapter(this, mcommentlist,                 r.layout.single_post, new string[] { tag_announcementid, tag_posted_date,                                 tag_deptno, tag_moduleid, tag_subject, tag_message},                         new int[] { r.id.announcementid, r.id.posted_date, r.id.deptno, r.id.moduleid,                         r.id.subject, r.id.message });          setlistadapter(adapter);           // optional: when user clicks list item          //could something.  however, choose         //to nothing...         listview lv = getlistview();             lv.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> parent, view view,                     int position, long id) { ]             }         });     }            public class loadcomments extends asynctask<void, void, boolean> {          @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(streamnotices.this);             pdialog.setmessage("loading notices...");             pdialog.setindeterminate(false);             pdialog.setcancelable(true);             pdialog.show();         }          @override         protected boolean doinbackground(void... arg0) {             updatejsondata();             return null;          }          @override         protected void onpostexecute(boolean result) {             super.onpostexecute(result);             pdialog.dismiss();             updatelist();         }     } } 

resultactivity.java

public class resultactivity extends activity {     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.anncm_fav);          listview lv = (listview) findviewbyid(r.id.outputlist);     } } 


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -