首页 > 代码库 > android listview无限循环显示数据

android listview无限循环显示数据

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("测试:"+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;
}
}
}

android listview无限循环显示数据