In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you how Android implements part of the layout monitoring ListView related knowledge points, the content is detailed, the logic is clear, I believe most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.
Android listview part of the layout monitoring, many people will think, directly in the adapter, get that layout, add click events, but I will tell you that at this time position is deranged, it is impossible to perform logical operations on each item according to the location of users' clicks. A solution that my colleague gave me is to set a tag for each layout in advance, that is, to bind the data that needs to be set. When you click on the event, there will be a view. According to the view, you can get the tag again and get the data in it. You can prevent the confusion problem and solve it successfully. The approximate code is as follows. Because of the need for encryption, many codes are omitted:
/ / Adapter public class OrAdapter extends BaseAdapter {@ Override public int getCount () {return dataMap.size ();} @ Override public Object getItem (int position) {return position;} @ Override public long getItemId (int position) {return position;} @ Override public View getView (int position, View convertView, ViewGroup parent) {ViewHolder viewHolder = null; if (convertView = null) {viewHolder = new ViewHolder () ConvertView = getActivity (). GetLayoutInflater (). Inflate (R.layout.activity_order_item, null); initViewHolder (convertView, viewHolder, position);} else {viewHolder = (ViewHolder) convertView.getTag ();} refreshViewHolder (position, viewHolder); return convertView;} private String getTag (String orderId, String instrument) {StringBuilder sb = new StringBuilder (); sb.append (orderId) .append (";") .append (instrument); return sb.toString () } private void refreshViewHolder (int position, ViewHolder viewHolder) {/ /-to prevent item from being reused-viewHolder.modeifyorder.setTag (getTag (orderid, instrument));} private void initViewHolder (View convertView, ViewHolder viewHolder, final int position) {viewHolder.modeifyorder = (RelativeLayout) convertView .findViewById (R.id.modeifyorder) ViewHolder.modeifyorder.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {int isman = (Integer) dataMap.get (position) .get ("ismanual"); int isprice = (Integer) dataMap.get (position). Get ("ispricereached"); String tag = v.getTag (). ToString (); String tagVec [] = tag.split (";"); long orderId = Long.parseLong (tagVec [0]) String instStr = tagVec [1];}}); convertView.setTag (viewHolder);} private class ViewHolder {TextView orderid; RelativeLayout modeifyorder;}} above is all the content of the article "how Android implements partial layout snooping ListView". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.