I'm reading about it and this has an effect on recent ListView
scrolling performance.
For easier scrolling, fast ListView
should avoid using OnClickListener
inside registerations Optimizer getView () method such as:
@ override public view getView (last integer status, seeviewview, ViewGroup parent) {ViewHolder holder; If (convertView == faucet) {holder = new ViewHolder (); LayoutInflator Wi = (Layout Inflator) getContext (). GetSystemService (References LAOUT_INFLATER_SERVICE); Convertview = vi.inflate (mResourceId, null); Holder.btn1 = (text view) convertviewfwbidid (ridbtn1); Holder Img1 = (TextView) ConvertViewFindVBIID (RID.IMG1); ConvertView.setTag (holder); } And {holder = (seeholder) ConvertView.gettag (); } Last item item = getItem (status); Holder.btn1.setText (item.btnText); Holder.img1.setBackgroundResource (item.imgSource); Holder.img1.setOnClickListener (New OnClickListener () {@Override Public Zero onClick (see v) {/ * .. my code use ARG block block .. *}} holder.btn1.setOnClickListener (New OnClickListener () {@ Override Public Zero onClick (see v) {/ *. Use of my code block. Position ARG .. * return convertView;}
If so, then enter a < Code> OnItemClickListener ListView
sample does a good practice as the following:
myListView.setOnItemClickListener (New OnItemClickListener () {@ Override public zero onIt EmClick (AdapterView & lt; & gt; arg0, see to see, integer position, long id) {if (view.getId () == R.id.btn1) {// my code block status using ARG} else If (view.getId () == R. Id.img1) {// my code block USING POSITION ARG}}};
It is better to use wrapper to access your see
and define your OnClickListener
For the first ( outside the adapter for better usability).
The following sample shows how to control 2 clickable on
on a single item of ListView
with good performance :
Public class item adapter baseEditor {Private list & lt; Items & gt; item; Private membrane cover = null; Private OnClickListener onMyItemClickListener1; Private OnClickListener onMyItemClickListener2; Public ItemAdapter (reference reference, item from the list, OnClickListener onMyItemClickListener1, OnClickListener onMyItemClickListener2) {this.inflater = LayoutInflater.from (reference); this. Item = item; This.onMyItemClickListener1 = onMyItemClickListener1; This.onMyItemClickListener2 = onMyItemClickListener2; } @ Override Public In Receipt () {Return items. Size (); } @OverWide public object will get ITM (status of int) {return item.get (status); } @ Override Public Long ITMID (Status of Intake) {Return Status; } @ Override Public Synchronized View GetView (View of Entitle, see conversionview, Version Group parent) {see line = convertview; If (line == tap) {row = inflater.inflate (R.Lite.Eight, empty); Cover = new item (line); Row.setTag (cover); } And {cover = (item wiper) line.Tet (); } Item items = get-up (position); . Wrapper.getClickView1 () setOnClickListener (onMyItemClickListener1); . Wrapper.getClickView2 () setOnClickListener (onMyItemClickListener2); Return (line); }} Public class ItemWrapper {Private View baseView; View View ClickView1; View ViewView2; Public itemwebper (see preview) {this.baseView = baseView; } View public getClickView1 () {if (clickView1 == faucet) {clickView1 = (see) baseView.findViewById (R.id.clickView1); } Return (Click View 1); } View public getClickView2 () {if (ClickView2 == faucet) {clickView2 = (see) baseView.findViewById (R.id.clickView2); } Return (click View2); }}
Comments
Post a Comment