android--inherits Simpleadapter to rewrite his getview

Source: Internet
Author: User



In the previous Android--listview implementation Simple list, a simple list binding was implemented with Simpleadapter. In this article, it is mainly by rewriting the GetView method, to see what the adapter internal bound data is roughly a process.


First join the implementation class:

Class Mtestadapter extends Simpleadapter {private context context;/* Run Environment */arraylist

We use this implementation class to replace the Simpleadapter we used earlier.

Mtestadapter listitemadapter=new Mtestadapter (Getbasecontext (),/* Indicates the operating environment of the simpleadapter Associated View, which is the current activity*/ listitem,/* A list of maps, each entry in the list corresponds to a row of the ListView, and each map contains all the key*/r.layout.listview_item,/* specified in the FROM parameter The resource ID of the layout file that defines the list item, which should contain at least the id*/new string[]{"ItemName"},/* to be added to the map map, as defined in the to parameter, Key*/new int[] {r.id.name}/* The ID of the view that binds the data corresponds to the from parameter, and the view elements that are bound should be all textview*/);//Set Adapter


After that run, look at the toast we added:




The Click event has been added, and by position, it is easy to distinguish between the item that we are currently working on and the action to be directed against the item. Especially when the item has a button on it, it's easier to rewrite the adapter.







Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

android--inherits Simpleadapter to rewrite his getview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.