android - ArrayAdapter's getView() method getting called automatically on EditText focus event -
i creating custom list activity. there 2 classes 1 having extended listactivity , other having arrayadapter list activity.
problem 1: problem while opening listactivity screen have search box on top of it. when start listactivity automatically opens keyboard current focus on edittext. want stop that.
problem 2: when focus goes on edittext arrayadapter's getview() method getting called automatically generating rows again. not getting why happens so. not calling notifydatasetchanged() method also. still when focus on edittext getview() called automatically. how prevent it?
storelistview.xml:
<?xml version="1.0" encoding="utf-8"?><linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@color/black" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:focusable="true" android:focusableintouchmode="true"> <tablelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <tablerow android:id="@+id/tablerow2" android:layout_height="wrap_content" android:gravity="center" android:layout_width="fill_parent" android:background="#919191"> <edittext android:id="@+id/searchtext" android:layout_width="fill_parent" android:layout_height="wrap_content" android:width="240dp" android:hint="search"></edittext> <imageview android:layout_width="wrap_content" android:src="@drawable/search" android:layout_height="wrap_content" android:id="@+id/searchimage"></imageview> </tablerow> </tablelayout> <listview android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <textview android:id="@+id/android:empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textcolor="@color/white" android:textsize="14sp" android:gravity="top|center" android:text="no store found.." /></linearlayout>
storelistview.java:
public class storelistview extends listactivity { private list<store> stores = new arraylist<store>(); private storelistrowadapter rowadapter; private runnable fetchstores; private handler handler = new handler(); private imageview searchimage; private edittext searchtext; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.storelistview); searchtext = (edittext) findviewbyid(r.id.searchtext); searchimage = (imageview) findviewbyid(r.id.searchimage); searchimage.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { } } }); rowadapter = new storelistrowadapter(this, r.layout.storelistview, stores); setlistadapter(rowadapter); fetchstores = new runnable() { @override public void run() { store store = new store(); storelistasyntask s = new storelistasyntask(); s.execute(store); } }; handler.post(fetchstores); } private runnable resultthread = new runnable() { public void run() { rowadapter.clear(); (int = 0; < stores.size(); i++) { store bean = stores.get(i); rowadapter.add(bean); } //rowadapter.notifydatasetchanged(); } }; class storelistasyntask extends asynctask<store, void, string> { private gson gson = new gson(); private list<store> storelist; private progressdialog m_progressdialog = null; @override protected string doinbackground(store... params) { return respdata; } @override protected void onpostexecute(string result) { //populate store list stores = storelist; runonuithread(resultthread); m_progressdialog.dismiss(); } }
}
storelistrowadapter.java :
public class storelistrowadapter extends arrayadapter<store> { list<store> stores; public storelistrowadapter(context context, int textviewresourceid, list<store> stores) { super(context, textviewresourceid, stores); this.stores = stores; } @override public view getview(int position, view convertview, viewgroup parent) { view view = convertview; if (view == null) { layoutinflater vi = (layoutinflater) getcontext().getsystemservice( context.layout_inflater_service); view = vi.inflate(r.layout.storelist_rowview, null); } final store store = stores.get(position); if (store != null) { linearlayout storelogocontainer = (linearlayout) view.findviewbyid(r.id.storelogocontainer); loaderimageview imageview = new loaderimageview(getcontext(), getcontext().getstring(r.string.logourl), store.getid().getid()); storelogocontainer.addview(imageview); textview storename = (textview) view.findviewbyid(r.id.storename); storename.settext(store.getstorename()); } return view; }
}
when start listactivity automatically opens keyboard current focus on edittext. want stop that.
give else focus, then.
also when focus goes on edittext arrayadapter's getview() method getting called automatically generating rows again.
getview()
called lots of times. may or may not "generating rows again". make sure getview()
implementation efficient.
how prevent it?
you don't. make sure getview()
implementation efficient.
Comments
Post a Comment