java - Calling notifyDataSetChanged() throws exception -
i have listview i'm binding adapter. adapter protected member of main class. have listener thread receives data , updates source list adapter. when call adapter's notifydatasetchanged() method, an exception thrown:
runtime exception: phonelayoutinflater(layoutinflater).inflate(int, viewgroup, boolean) line: 322
i've read notifydatasetchanged() method has called on ui thread, , i'm doing that. in fact, sure, update listview's data source on ui thread. in listener thread update protected member houses data. here's example of i'm doing (note don't have part of code calls asynctask, it's fired listener):
public class main extends activity() { protected linkedlist<hashmap<string, string>> adapterdatalist = new linkedlist<hashmap<string, string>>(); protected mydataobject dataobject; protected simpleadapter dataadapter; @override public void oncreate(bundle savedinstancestate) { //call parent oncreate super.oncreate(savedinstancestate); //display main form setcontentview(r.layout.main); //get handle on score list view elements listview datalist = (listview)(findviewbyid(r.id.datalist)); //link adapter , data source dataadapter = new simpleadapter(this, adapterdatalist, r.layout.row, new string[]{"name","address"}, new int[]{r.id.username,r.id.address}); datalist.setadapter(dataadapter); } protected void refreshdata() { adapterdatalist.clear(); iterator<mydata> iter = mydataobject.iterator(); while(iter.hasnext()) { hashmap<string, string> item = new hashmap<string, string>() item.put("name", iter.name); item.put("address", iter.address); adapterdatalist.add(item); } dataadapter.notifydatasetchanged(); } private class datatask extends asynctask<data, void, data> { protected void onpostexecute(data data) { dataobject = data; runonuithread (new runnable() { public void run() { refreshscores(); }}); } } ... }
does have pointers or ideas why i'm getting exception? appreciated.
edit here layout files, requested: main.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ptl="http://schemas.android.com/apk/res/com.mod0.pubtrivialive" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/datalistcontainer"> <listview android:id="@+id/datalist" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout>
row.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="wrap_content" android:orientation="horizontal" android:paddingbottom="6dip" android:paddingtop="4dip"> <textview android:id="@+id/name" android:layout_width="80dip" android:layout_height="wrap_content" /> <textview android:id="@+id/address" android:layout_height="wrap_content" android:layout_weight="1" /> </linearlayout>
this doesn't right datalist.clear();
. sure you're meaning call clear on datalist
, not adapterdatalist
?
Comments
Post a Comment