I got some errors when I create an header listview on xamarin android -


  public class customadapter : baseadapter{    	private  const int type_item = 0;  	private const int type_separator = 1;    	private list<string> mdata;  	private treeset sectionheader;    	private layoutinflater minflater;    	public customadapter(context context) {  		minflater = (layoutinflater) context  			.getsystemservice(context.layoutinflaterservice);  	}    	public void additem( string item) {  		mdata.add(item);  		notifydatasetchanged();  	}    	public void addsectionheaderitem(string item) {  		mdata.add(item);  		sectionheader.add(mdata.count - 1);  		notifydatasetchanged();  	}    	public int getitemviewtype(int position) {  		return sectionheader.contains(position) ? type_separator : type_item;  	}      	public int getviewtypecount {  		get{ return 2; }  	}      	public override int count {  		get {return mdata.count;}  	}      	public override getitem this[int position] {  		get{ return mdata [position]; }  	}  		  	public override long getitemid(int position) {  		return position;  	}     	public view getview(int position, view convertview, viewgroup parent) {  		viewholder holder = null;  		int rowtype = getitemviewtype(position);    		if (convertview == null) {  			holder = new viewholder();  			switch (rowtype) {  			case type_item:  				convertview = minflater.inflate(resource.layout.textviewitemsseparator, parent);  				holder.textview = (textview) convertview.findviewbyid(resource.id.textviewheaderitems);  				break;  			case type_separator:  				convertview = minflater.inflate(resource.layout.textviewheaderitems, parent);  				holder.textview = (textview) convertview.findviewbyid(resource.id.textviewitemsseparator);  				break;  			}  			convertview.tag=holder;  		} else {  			holder = (viewholder)convertview.tag viewholder;  		}  		holder.textview.text=mdata[position];    		return convertview;  	}    	public  class viewholder:java.lang.object {  		public textview textview;  	}

onactivitycreated:  madapter=new customadapter(this);  			for (int = 0; <= items.count; i++) {  				madapter.additem (items [i].tostring ());  				if (i == 0) {  					madapter.addsectionheaderitem ("music");  				} else if(i==13) {  					madapter.addsectionheaderitem ("audio");  				}  			}  			lst.adapter = new customadapter (activity, madapter);

create custom adapter listview

you must override getviewtypecount() method. method returns number of types of views created getview method.

i trying create header listview.

set text using property of textview

holder.textview.text = mdata[position]; 

under hood, xamarin converts c# string java charsequence , calls settext you.


p.s

you have @ documentation! must when you're beginner.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -