zoukankan      html  css  js  c++  java
  • Android(java)学习笔记137:ListView编写步骤(重点)

    1.ListView在我们的手机android编写程序中使用是十分广泛的,比如如下图中 短信手机设置 都是ListView的效果:

    手机设置:

               

    短信:

      

    2.正因为这样的重要性,我们不得不说一下ListView编写的步骤:

    (1)xml布局文件,声明listview的控件

        <ListView

               android:layout_width="match_parent"

               android:layout_height="match_parent"

               android:id = "@+id/lv"

        </ListView>

    (2)在代码里面查找listview

             findViewById(R.id.lv);

    (3)设置listview的数据适配器

            lv.setAdapter(new MyAdapter());

    (4)编写数据适配器

           private class MyAdapter extends BaseAdapter {

                            public int getCount() {

                                  return  ......;//告诉listview里面有多少条数据

                      }

                           public View getView(int positon,  View  convertView,   ViewGroup  parent) {

                                 return ......;//返回每个位置上显示的view是什么样子的

                      }

    }

  • 相关阅读:
    1074. Reversing Linked List (25)
    1056. Mice and Rice (25)
    1051. Pop Sequence (25)
    1001. A+B Format (20)
    1048. 数字加密(20)
    1073. Scientific Notation (20)
    1061. Dating (20)
    1009. 说反话 (20)
    MyBatis学习总结(8)——Mybatis3.x与Spring4.x整合
    MyBatis学习总结(8)——Mybatis3.x与Spring4.x整合
  • 原文地址:https://www.cnblogs.com/hebao0514/p/4755532.html
Copyright © 2011-2022 走看看