Sunday, 15 June 2014

android - Add new item in the Listview is already populate the start of app -



android - Add new item in the Listview is already populate the start of app -

my listview populated @ origin of application using listfragment , baseadapter. in layout have button add together new item, when add together new item in listview items deleted.

my listfragment.cs:

public class tabitems : listfragment { adapteritems _adaptador; public override view oncreateview (layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate (resource.layout.items, null); listview listview = (listview)view.findviewbyid (android.resource.id.listitems); _adaptador = new adapteritems(this.activity, webservice.returnlistitems()); listview.adapter = _adaptador; homecoming view; } public override void onlistitemclick(listview l, view v, int position, long id) { bundle bundle = new bundle(); intent activity = new intent(v.context, typeof(chatactivity)); int value = (int)l.adapter.getitem(position); bundle.putint("value", value); activity.putextras(bundle); startactivity(activity); } }

my activity.cs

list<string> _list = new list<string>(); arrayadapter<string> _adapter; listview _listview; protected override void oncreate(bundle bundle) { base.oncreate(bundle); setcontentview(resource.layout.telachat); utilpop.createlistviewwithitems(); // populate listview in start _listview = findviewbyid<listview>(resource.id.listitems); imagebutton btnadditem = findviewbyid<imagebutton>(resource.id.botaoadditem); btnadditem.click += btnadditem_click; } void btnadditem_click(object sender, eventargs e) { edittext edttxitem = findviewbyid<edittext>(resource.id.itemname); additem(edttxmensagem.text); } //add new item in listview private void additem(string itemname) { _list.add(itemname); _adapter = new arrayadapter<string>(this, android.resource.layout.simplelistitem1, _list); _listview.adapter = _adapter; _listview.defernotifydatasetchanged(); }

android listview android-listview xamarin

No comments:

Post a Comment