java - No data available listview -
i ran problem creating listview in android app.
this code:
public class mainactivity extends listactivity { private simpleadapter emadapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // set layout view setcontentview(r.layout.main_ui_layout); final utility utility = new utility(this); utility.getfiles(); final listview filelistview = (listview) findviewbyid(android.r.id.list); filelistview.setemptyview(findviewbyid(r.id.progressbar)); // create hashmap items final arraylist<hashmap<string, string>> listitems = new arraylist<hashmap<string, string>>(); // using thread simulate download of data thread emthread = new thread(new runnable() { public void run() { // waiting 3s try { thread.sleep(2500); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } // looping through item nodes <item> (int em = 0; em < utility.filemap.size(); em++) { hashmap<string, string> emmap = new hashmap<string, string>(); file files = new file(utility.filemap.get("duroodsharif")); emmap.put(files.getname(), utility.filemap.get("duroodsharif")); listitems.add(emmap); } } }); // stop progress bar utility.stopprogressbar(); // adding listitems listview emadapter = new simpleadapter(this, listitems, r.layout.list_item, new string[] { getstring(r.string.title_id), getstring(r.string.description_id) }, new int[] { r.id.title, r.id.desciption }); runonuithread(new runnable() { @override public void run() { // set list adapter filelistview.setadapter(emadapter); } }); emthread.start(); // later there's no data thread mythread = new thread(new runnable() { public void run() { // waiting 3s try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } listitems.clear(); runonuithread(new runnable() { // run on ui thread setthe // adapter list public void run() { filelistview.setemptyview(findviewbyid(r.id.emptytext)); emadapter.notifydatasetchanged(); } }); } }); mythread.start(); // selecting single listview item listview emlistview = getlistview(); emlistview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // getting values selected listitem string title = ((textview) view.findviewbyid(r.id.title)).gettext().tostring(); string description = ((textview) view.findviewbyid(r.id.desciption)).gettext().tostring(); // starting new intent intent in = new intent(getapplicationcontext(), singlemenuitemactivity.class); in.putextra(getstring(r.string.title_id), title); in.putextra(getstring(r.string.description_id), description); startactivity(in); } }); }
and layout file
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/app_background_portrait_type2" android:orientation="vertical" > <listview android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <progressbar android:id="@+id/progressbar" style="?android:attr/progressbarstylelarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="gone" /> <textview android:id="@+id/emptytext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="no data available" android:visibility="gone" />
'
what trying achieve showing progress bar till listview not filled data progress bar displaying continuously. adding name of mp3 file asset folder in map , adding map in listitems , till process going showing progress bar.
can point me right direction?
thanks in advance.
as exception stands, can not call wait()
, notify()/notifyall()
without synchronized
block.
probably want call emadapter.notifydatasetchanged()
instead of emadapter.notifyall();
object.notifyall()
wake thread waiting on object
. need?
Comments
Post a Comment