how to display data stored in an array for android using C# and ListView -


i have following code written in c# using xamarin android:

edittext nametext = findviewbyid<edittext> (resource.id.editname);         button btnaddcontact = findviewbyid<button> (resource.id.btnaddcontact);          listview contactview = findviewbyid<listview> (resource.id.listview1);          btnaddcontact.click += delegate {             string[] contactarr = nametext.text.split('\n');         }; 

first off.. data input edittext field stored array contactarr when btnaddcontact clicked? there no build errors wasn't sure if work..

my main question is, if data has been stored array, how go displaying data in list view? code example me world of don't have clue go this.. thanks.

edit new code tried.

edittext nametext = findviewbyid<edittext> (resource.id.editname);         button btnaddcontact = findviewbyid<button> (resource.id.btnaddcontact);          listview contactview = findviewbyid<listview> (resource.id.listview1);           btnaddcontact.click += delegate {             string[] contactarr = nametext.text.split('\n');              var myadapter = new arrayadapter(this, resource.id.listview1, contactarr);             contactview.adapter = myadapter;         }; 

edit error list:

you must supply resource id textview shutting down vm fatal exception: main java.lang.illegalstateexception: arrayadapter requires resource id textview @ android.widget.arrayadapter.createviewfromresource(arrayadapter.java:386) @ android.widget.arrayadapter.getview(arrayadapter.java:362) @ android.widget.abslistview.obtainview(abslistview.java:2159) @ android.widget.listview.measureheightofchildren(listview.java:1246) @ android.widget.listview.onmeasure(listview.java:1158) @ android.view.view.measure(view.java:15518) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4825) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1404) @ android.widget.linearlayout.measurehorizontal(linearlayout.java:1052) @ android.widget.linearlayout.onmeasure(linearlayout.java:590) @ android.view.view.measure(view.java:15518) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4825) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1404) @ android.widget.linearlayout.measurevertical(linearlayout.java:695) @ android.widget.linearlayout.onmeasure(linearlayout.java:588) @ android.view.view.measure(view.java:15518) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4825) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.view.view.measure(view.java:15518) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4825) @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1404) @ android.widget.linearlayout.measurevertical(linearlayout.java:695) @ android.widget.linearlayout.onmeasure(linearlayout.java:588) @ android.view.view.measure(view.java:15518) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4825) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2176) @ android.view.view.measure(view.java:15518) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1874) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1089) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1265) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:989) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4351) @ android.view.choreographer$callbackrecord.run(choreographer.java:749) @ android.view.choreographer.docallbacks(choreographer.java:562) @ android.view.choreographer.doframe(choreographer.java:532) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:735) @ android.os.handler.handlecallback(handler.java:725) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5041) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) @ dalvik.system.nativestart.main(native method) caused by: java.lang.classcastexception: android.widget.linearlayout cannot cast android.widget.textview @ android.widget.arrayadapter.createviewfromresource(arrayadapter.java:379) ... 45 more

listview stupid control, not know data itself, needs adapter takes care of how format data.

to display alphanumerical values edittext has been split array, can use arrayadapter built android.

var myadapter = new arrayadapter(this, resource.layout.simplelistitem1, contactarr); 

the listview needs know adapter have do:

contactview.adapter = myadapter; 

all basic stuff can find lot of information on in xamarin developer center. xamarin has nice github repository loads , loads of samples.

edit:

add resource folder , call textviewitem.xml:

<?xml version="1.0" encoding="utf-8"?> <textview xmlns:android="http://schemas.android.com/apk/res/android"      android:id="@+id/textitem"      android:textsize="44sp"            android:layout_width="fill_parent"      android:layout_height="wrap_content" /> 

and alter arrayadapter match this:

var myadapter = new arrayadapter(this, resource.layout.textviewitem, contactarr); 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -