In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to understand SparseBooleanArray, the content is very detailed, interested friends can use for reference, hope to be helpful to you.
The problem of multiple selection lists is often encountered in the course of a project. The problem is not troublesome, but it seems that each implementation is different, or non-standard. I have been using HashMap to record the selection of lists, but I have been thinking about the suggestion of using SparseBooleanArray. The heart is very impetuous, calm down to sum up a knowledge point unexpectedly to the need for "time, earth and human harmony" to the point.
SparseBooleanArray is a utility class provided by android, which has been translated into "sparse array". It is specially provided for mobile phones, a platform with scarce memory resources. According to its source code, it is more efficient than HashMap in a small number of cases. The Integer here is the equivalent of an index, while in SparseArray this index uses dichotomy lookups.
Public class MyAdapter extends ArrayAdapter {private Context mContext; private List mData; private SparseBooleanArray selectList = new SparseBooleanArray (); MyAdapter (@ NonNull Context context, @ LayoutRes int resource, @ NonNull List objects) {super (context, resource, objects); this.mContext = context; this.mData = objects; initSelectList () } @ NonNull @ Override public View getView (final int position, @ Nullable View convertView, @ NonNull ViewGroup parent) {if (convertView = = null) {convertView = LayoutInflater.from (mContext) .propagate (R.layout.item_choice, parent, false);} TextView text = (TextView) convertView.findViewById (R.id.text); CheckBox box = (CheckBox) convertView.findViewById (R.id.checkbox) Text.setText (getItem (position)); box.setChecked (selectList.get (position)); box.setOnCheckedChangeListener (new CompoundButton.OnCheckedChangeListener () {@ Override public void onCheckedChanged (CompoundButton buttonView, boolean isChecked) {selectList.put (position, isChecked);}}); return convertView } void initSelectList () {/ / uncheck for (int I = 0; I < mData.size (); iTunes +) {selectList.put (I, false);} notifyDataSetChanged ();} void checkAll () {/ / Select all for (int I = 0; I < mData.size (); iTunes +) {selectList.put (I, true) } notifyDataSetChanged ();} void reverse () {/ / invert for (int I = 0; I < mData.size (); iTunes +) {if (selectList.get (I)) {selectList.put (I, false);} else {selectList.put (I, true);}} notifyDataSetChanged () } SparseBooleanArray getSelectedList () {return selectList;}} on how to understand SparseBooleanArray to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.