Android custom Adapter

Source: Internet
Author: User

Public classMyListViewAdapter extendsBaseAdapter {

PrivateContext mContext = null;
PrivateLayoutInflater mLayoutInflater = null;
PrivateList <Map <String, Object> mList = null;

// Constructor. The parameter list passes the information of this group of data.
PublicMyListViewAdapter (Context context, List <Map <String, Object> list ){
This. mList = list;
This. mContext = context;
This. mLayoutInflater = LayoutInflater. from (mContext );
}
 
// Obtain the total number
@ Override
Public intgetCount (){
// TODOAuto-generated method stub
Return this. mList! = Null? This. mList. size (): 0;
}
 
// Obtain the View object by location
@ Override
PublicObject getItem (intposition ){
// TODOAuto-generated method stub
Return this. mList. get (position );
}
 
// Obtain the ID in the List based on the position of the ListView.
@ Override
Public longgetItemId (intposition ){
// TODOAuto-generated method stub
Returnposition;
}
 
// Obtain the View object by location
@ Override
PublicView getView (intposition, View convertView, ViewGroup parent ){
// TODOAuto-generated method stub
// Obtain the child components in the entry
ViewHolder holder = null;
If (convertView = null ){
Holder = newViewHolder ();
ConvertView = mLayoutInflater. inflate (R. layout. activity_main_item, null );
Holder. imageHead = (ImageView) convertView. findViewById (R. id. imageHead );
Holder. name = (TextView) convertView. findViewById (R. id. name );
Holder. time = (TextView) convertView. findViewById (R. id. time );
Holder. content = (TextView) convertView. findViewById (R. id. content );
Holder. imageContent = (ImageView) convertView. findViewById (R. id. imageContent );
Holder. transmit = (TextView) convertView. findViewById (R. id. transmit );
Holder. comment = (TextView) convertView. findViewById (R. id. comment );
ConvertView. setTag (holder );
} Else {
Holder = (ViewHolder) convertView. getTag ();
}

// Operations on the controls in the items of ListView
Holder. imageHead. setImageResource (Integer) mList. get (position). get ("imageHead "));
Holder. name. setText (mList. get (position). get ("name"). toString ());
Holder. time. setText (mList. get (position). get ("time"). toString ());
Holder. content. setText (mList. get (position). get ("content"). toString ());
Holder. imageContent. setImageResource (Integer) mList. get (position). get ("imageContent "));
Holder. transmit. setText (mList. get (position). get ("transmit"). toString ());
Holder. comment. setText (mList. get (position). get ("comment"). toString ());

ReturnconvertView;
} Www.2cto.com

// Define an internal class to manage sub-components in the entry
Public final classViewHolder {
PublicImageView imageHead = null;
PublicImageView imageContent = null;
PublicTextView time = null;
PublicTextView name = null;
PublicTextView content = null;
PublicTextView comment = null;
PublicTextView transmit = null;
}
 
}

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.