Use of Android learning--listview (iv)

Source: Internet
Author: User

Implementation of the ListView based on Baseadapter


Note the following four methods need to be rewritten to extend Baseadapter

GetCount ();

GetItem ();

Getitemid ();

GetView ();


List of programs

Package xiaocool.net.listviewtest;import android.graphics.color;import android.os.bundle;import  android.support.v7.app.ActionBarActivity;import android.view.View;import  Android.view.viewgroup;import android.widget.baseadapter;import android.widget.imageview;import  android.widget.LinearLayout;import android.widget.ListView;import android.widget.TextView; public class mainactivity extends actionbaractivity {   private  listview list;     @Override     protected void oncreate ( Bundle savedinstancestate)  {        super.oncreate ( Savedinstancestate);         setcontentview (R.LAYOUT.LISTVIEW2);         list= (ListView) This.findviewbyid (r.id.list1);         /*//defines an array         string arr[]={"School Cool Network 1", "School Cool Network 2", "School Cool Network 3", "School Cool Network 4", "School Cool network 5"};         //wrapping an array into a arrayadapter        arrayadapter <String> adapter=new ArrayAdapter<String> (This,r.layout.array_item,r.id.textview,arr);         list.setadapter (Adapter);*/         baseadapter adapter=new baseadapter ()  {             //returns the total number of list items               @Override             public int  getcount ()  {                 return 20;            }              @Override              public object getitem (int position)  {                 return null;             }          //returns the ID of a list item              @Override              public long getitemid (int position)  {                 return 0;             }            //returns the appearance of each specific item               @Override              public view getview (int position,  View convertview, viewgroup parent)  {                //Create a LinearLayout and add two controls to it                  linearlayout layout=new linearlayout ( Mainactivity.this);                 layout.setorientation (0);                 imageview imageview=new imageview (mainactivity.this);                 imageview.setimageresource ( R.drawable.syudio);                 textview textview=new texTView (mainactivity.this);                 textview.settext ("position+1" + "item");                 textview.settextcolor (Color.Blue);                 textview.settextsize (;   )              layout.addview (ImageView);                 layout.addview ( TextView);                 return layout;            }         };        list.setadapter (adapter);     }}

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/41/wKioL1UD7bqj2Sr1AAJvTv38BmU388.jpg "title=" Screenshot_2015-03-14-16-07-49.png "alt=" Wkiol1ud7bqj2sr1aajvtv38bmu388.jpg "/>

Use of Android learning--listview (iv)

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.