java - Empty List View (list fragment) -
when app running see empty layout "no data". can do? trying asynctask, doesent work. dont know do. im android newbie. may used wrong way? , trying inflate view not idea?
public class myemployefragment extends listfragment { mytask task; static string employer_id; static string employer_name; static string employer_last_name; string str = null; arraylist<spr_item> ret_data = null; // имена атрибутов для map final string attribute_id = "p_id"; final string attribute_name = "p_name"; final string attribute_last_name = "p_last_name"; view v; listview listview; simpleadapter sadapter; listview lvsimple; @override public void onattach(activity activity) { super.onattach(activity); task = new mytask(); task.execute(); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.my_employe, container, false); listview = (listview) v.findviewbyid(android.r.id.list); // updating action bar title getactivity().getactionbar(); // массивы данных // string[] userid = {employer_id}; // string[] username = {employer_name}; // string[] userlatname = {employer_last_name}; ret_data = new arraylist<spr_item>(); //ret_data.add(new spr_item("11","22","33")); //ret_data.add(new spr_item("111","222","333")); //ret_data.add(new spr_item("1111","2222","3333")); // упаковываем данные в понятную для адаптера структуру arraylist<map<string, object>> data = new arraylist<map<string, object>>( ret_data.size()); map<string, object> m; (int = 0; < ret_data.size(); i++) { m = new hashmap<string, object>(); m.put(attribute_id, ret_data.get(i).getid() ); m.put(attribute_name,ret_data.get(i).getname() ); m.put(attribute_last_name,ret_data.get(i).getlastname() ); data.add(m); } // массив имен атрибутов, из которых будут читаться данные string[] = { attribute_id, attribute_name,attribute_last_name}; // массив id view-компонентов, в которые будут вставлять данные int[] = { r.id.tw_employe_id ,r.id.tw_employe_name, r.id.tw_employe_last_name}; // создаем адаптер simpleadapter sadapter = new simpleadapter(getactivity(), data, r.layout.list_item_employee, from, to); // определяем список и присваиваем ему адаптер lvsimple = (listview) v.findviewbyid(android.r.id.list); lvsimple.setadapter(sadapter); return v; } class mytask extends asynctask<void, void, void> { @override protected void onpreexecute() { super.onpreexecute(); } @override protected void doinbackground(void... params) { string s = "5acacec6-752b-4eff-aa50-eebe58a52113"; // string user_guid = myprefs.getstring("guid", ""); httpactivity _http = new httpactivity("192.168.10.11", "80"); _http.set_addr_protocol("/website/p/spr/spr.aspx/"); _http.add_param("query", "spr_employee_get"); // _http.add_param("p_guid", user_guid.tostring().trim()); _http.add_param("p_guid", s); _http.send(); ret_data = _http.getarrayparamvalue(); //employer_name = _http.getarrayparamvalue("p_name"); //employer_id = _http.getarrayparamvalue("p_id"); //employer_last_name = _http.getarrayparamvalue("p_last_name"); return null; } @override protected void onpostexecute(void result) { super.onpostexecute(result); } } }
that's because when instantiate adapter data empty. should either set adapter in onpostexecute method of asynctask, or call sadapter.notifydatasetchanged
adapter update views data obtained
Comments
Post a Comment