Android listview displays data in an infinite loop, androidlistview

Source: Internet
Author: User

Android listview displays data in an infinite loop, androidlistview
Package com. example. listview;


Import java. util. ArrayList;
Import java. util. List;


Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. ViewGroup;
Import android. widget. BaseAdapter;
Import android. widget. ListView;
Import android. widget. TextView;


Public class MainActivity extends Activity {
Private List <String> datas;
Private ListView lv;
Private MyAdapter adapter;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
Datas = new ArrayList <String> ();
Lv = (ListView) findViewById (R. id. lv );
For (int I = 0; I <20; I ++ ){
Datas. add ("test:" + I );
}
Adapter = new MyAdapter ();
Lv. setAdapter (adapter );
}

Class MyAdapter extends BaseAdapter {


@ Override
Public int getCount (){
// TODO Auto-generated method stub
Return Integer. MAX_VALUE;
}


@ Override
Public Object getItem (int arg0 ){
// TODO Auto-generated method stub
Return null;
}


@ Override
Public long getItemId (int arg0 ){
// TODO Auto-generated method stub
Return 0;
}


@ Override
Public View getView (int arg0, View arg1, ViewGroup arg2 ){
TextView TV = new TextView (MainActivity. this );
TV. setTextSize (16 );
String content = datas. get (arg0% 20 );
TV. setText (content );
Return TV;
}
}
}

Related Article

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.