android 基础一 <ListView>

 1 public class ListViewActivity extends AppCompatActivity {
 2     ListView lvData;
 3     @Override
 4     protected void onCreate(Bundle savedInstanceState) {
 5         super.onCreate(savedInstanceState);
 6         setContentView(R.layout.activity_list_view);
 7         lvData=(ListView)findViewById(R.id.lvData);
 8         lvData.setAdapter(new MyAdapter());
 9         new QueueTest().start();
10     }
11     public class MyAdapter extends BaseAdapter {
12         int count=0;
13         @Override
14         public int getCount() {
15             return 10;
16         }
17         @Override
18         public Object getItem(int position) {
19             return null;
20         }
21         @Override
22         public long getItemId(int position) {
23             return 0;
24         }
25         @Override
26         public View getView(int position, View convertView, ViewGroup parent) {
27             TextView textView=null;
28             if(convertView!=null){
29                 textView=(TextView)convertView;
30             }else{
31                 textView=new TextView(getApplicationContext());
32             }
33 
41             textView.setText("测试数据:"+(++count));
42             return textView;
43         }
44         @Override
45         public CharSequence[] getAutofillOptions() {
46             return new CharSequence[0];
47         }
48     }
49 
50 }

 

posted @ 2019-06-07 22:39  zp007  阅读(91)  评论(0编辑  收藏  举报