Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

java - how to show data in listview from web service in android -


my webservice return data in format

ab cdef have show return data in listview here welcome.xml in have display data

welcome.xml

  <?xml version="1.0" encoding="utf-8" ?>  - <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">   <imageview android:id="@+id/welcome" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/main" android:layout_gravity="center_horizontal" />    -  - <relativelayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margintop="10dip" android:id="@+id/relative01">   <listview android:id="@+id/lvevent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/welcome" android:background="@drawable/wel_bg" android:layout_marginbottom="50dip" />    </relativelayout> - <tablelayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="@+id/relative01"> - <tablerow>   <button android:id="@+id/btn_index" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/cap_button" android:paddingright="15dip" android:layout_marginright="50dip" />    <button android:id="@+id/btn_event" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/button" android:layout_torightof="@+id/btn_index" android:paddingleft="25dip" android:layout_marginleft="30dip" />    </tablerow>   </tablelayout>   </linearlayout> 

how can show data in listview.

following code using parser:

myxmlhandler.java :

package org.parsing;  import org.xml.sax.attributes; import org.xml.sax.saxexception; import org.xml.sax.helpers.defaulthandler;    public class myxmlhandler extends defaulthandler{  boolean currentelement = false;  string currentvalue = null;  public static siteslist siteslist = null;   public static siteslist getsiteslist() {   return siteslist;  }   public static void setsiteslist(siteslist siteslist) {   myxmlhandler.siteslist = siteslist;  }   /** called when tag starts ( ex:- <name>androidpeople</name>    * -- <name> )*/  @override  public void startelement(string uri, string localname, string qname,    attributes attributes) throws saxexception {    currentelement = true;    if (localname.equals("content"))   {    /** start */     siteslist = new siteslist();   } /*else if (localname.equals("website")) {    *//** attribute value *//*    string attr = attributes.getvalue("category");    siteslist.setcategory(attr);   }*/   }   /** called when tag closing ( ex:- <name>androidpeople</name>    * -- </name> )*/  @override  public void endelement(string uri, string localname, string qname)    throws saxexception {    currentelement = false;    /** set value */    if (localname.equalsignorecase("title"))    siteslist.settitle(currentvalue);   else if (localname.equalsignorecase("description"))    siteslist.setdescription(currentvalue);   }   /** called tag characters ( ex:- <name>androidpeople</name>    * -- androidpeople character ) */  public void characters(char[] ch, int start, int length)    throws saxexception {    if (currentelement) {    currentvalue = new string(ch, start, length);    currentelement = false;   }   }   } 

siteslist.java:

package org.parsing;  import java.util.arraylist;  public class siteslist {   /** variables */  private arraylist<string> title = new arraylist<string>();  private arraylist<string> description = new arraylist<string>();  //private arraylist<string> category = new arraylist<string>();    /** in setter method default return arraylist    *  change add  */   public arraylist<string> gettitle() {   return title;  }   public void settitle(string title) {   this.title.add(title);  }   public arraylist<string> getdescription() {   return description;  }   public void setdescription(string description) {   this.description.add(description);  }   /*public arraylist<string> getcategory() {   return category;  }   public void setcategory(string category) {   this.category.add(category);  } */ } 

xmlparsingexample.java:

package org.parsing;  import java.net.url;  import javax.xml.parsers.saxparser; import javax.xml.parsers.saxparserfactory;  import org.xml.sax.contenthandler; import org.xml.sax.inputsource; import org.xml.sax.xmlreader;   import android.app.activity; import android.os.bundle; import android.widget.linearlayout; import android.widget.textview;  public class xmlparsingexample extends activity {  /** create object sitelist class */  siteslist siteslist = null;   /** called when activity first created. */  @override  public void oncreate(bundle savedinstancestate) {   super.oncreate(savedinstancestate);   setcontentview(r.layout.main);    /** create new layout display view */   linearlayout layout = new linearlayout(this);   layout.setorientation(1);    /** create new textview array display results */   textview title[];   textview description[];   //textview category[];    try {     /** handling xml */    saxparserfactory spf = saxparserfactory.newinstance();    saxparser sp = spf.newsaxparser();    xmlreader xr = sp.getxmlreader();     /** send url parse xml tags */    url sourceurl = new url(      "http://208.109.97.179:1010/webservices/newsevents.php");     /** create handler handle xml tags ( extends defaulthandler ) */    myxmlhandler myxmlhandler = new myxmlhandler();    xr.setcontenthandler((contenthandler) myxmlhandler);    xr.parse(new inputsource(sourceurl.openstream()));    } catch (exception e) {    system.out.println("xml pasing excpetion = " + e);   }    /** result myxmlhandler sitleslist object */   siteslist = myxmlhandler.siteslist;    /** assign textview array lenght arraylist size */   title = new textview[siteslist.gettitle().size()];   description = new textview[siteslist.getdescription().size()];   //category = new textview[siteslist.getname().size()];    /** set result text in textview , add layout */   (int = 0; < siteslist.gettitle().size(); i++) {    title[i] = new textview(this);    title[i].settext("title = "+siteslist.gettitle().get(i));    description[i] = new textview(this);    description[i].settext("website = "+siteslist.getdescription().get(i));    //category[i] = new textview(this);    //category[i].settext("website category = "+siteslist.getcategory().get(i));     layout.addview(title[i]);    layout.addview(description[i]);    //layout.addview(category[i]);   }    /** set layout view display */   setcontentview(layout);   }  } 

after checking code tell me wrong , tell correct answer.

one solution can be, parse xml response web service , store parsed data in array(s). use array adapter populate listview.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -