In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to use the encapsulated adapter adapter? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
/ / encapsulated adapter class adapterpublic class NewJobAdapter extends BaseAdapter {private List data = null;private LayoutInflater mInflater = null;private Context mContext;public NewJobAdapter () {} public NewJobAdapter (Context context, List list) {/ / load the layout this.mInflater = LayoutInflater.from (context) according to the context context; mContext = context;data = list;} @ Overridepublic int getCount () {/ / the number of entries in the dataset represented in this adapter () } @ Overridepublic Object getItem (int position) {/ / get the data item corresponding to the specified index in the dataset return position;} @ Overridepublic long getItemId (int position) {/ / get the row corresponding to the specified index in the list idreturn position;} / / get a view of the specified index in the dataset to display the data @ Overridepublic View getView (int position, View convertView, ViewGroup parent) {ViewHolder holder = null / / if the cache convertView is empty, you need to create a Viewif (convertView = = null) {holder = new ViewHolder (); / / load the layout convertView = mInflater.inflate (R.layout.item_list_new_job, null) according to the custom Item layout; holder.img = (ImageView) convertView.findViewById (R.id.id_img); holder.time = (TextView) convertView.findViewById (R.id.id_time); holder.address = (TextView) convertView.findViewById (R.id.id_address) Holder.message = (TextView) convertView.findViewById (R.id.id_message); holder.price = (TextView) convertView.findViewById (R.id.id_price); / / Save the set layout to the cache and set it in Tag so that it is easy to retrieve TagconvertView.setTag (holder) later;} else {holder = (ViewHolder) convertView.getTag ();} holder.img.setBackgroundResource ((Integer) data.get (position) .get ("img")) Holder.time.setText ((String) data.get (position) .get ("time"); holder.message.setText ((String) data.get (position) .get ("area")); holder.address.setText ((String) data.get (position) .get ("position")); return convertView;} / * ViewHolder static class * picture * job * time * part-time location * price * / static class ViewHolder {public ImageView img;public TextView message Public TextView time;public TextView address;public TextView price;}} / / activity calls public class NewJobActivity extends Activity implements OnItemClickListener {private List data = null;private List list;private ListView mListView;private NewJobAdapter adapter;@Overrideprotected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); getWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView (R.layout.activity_new_job); mListView = (ListView) findViewById (R.id.new_job_list); mListView.setOnItemClickListener (this); data = getData () / / get data adapter = new NewJobAdapter (this, data); mListView.setAdapter (adapter);} private List getData () {list = new ArrayList (); Map map;for (int iTun0) I the answer to the question about how to use the encapsulated adapter adapter is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.