ListView和Adapter

1.简单Adapter

     其中的主要是两个函数的使用:

     a.得到一个Adapter

             new ArrayAdapter<String> (Context context, int textViewResourceId, List<String> objects)

    b.使用ListView的setAdapter()方法

         setAdapter()(ListAdapter adapter)

ListView和Adapter

 

2.simpleCursorAdapter的用法

      a.得到一个Cursor对象

         query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

          Cursor cursor = getContentResolver.query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);

         b.得到一个 SimpleCursorAdapter对象

             SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)

             

 

ListView和Adapter

 

3.simpleAdapter的用法

SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
得到一个SimpleAdapter对象,重点是getData函数(将得到的数据保存在一个List里面)

ListView和Adapter

 

4.自定义Adapter的用法

    1.继承BaseAdapter类

    2.重写getView()--每一项显示成什么样有它决定 

        getView(int position, View convertView, ViewGroup parent)

         可以在这个函数中实现Button的setOnClickListener事件

    3.重写getCount()--一共有多少项由它决定

    4.实现OnItemClickListener事件--为每一项添加事件实现

       在布局文件中的LinearLayout添加   android:descendantFocusability="blocksDescendants";

     Button中添加android:focusable="false"

       可以完成setOnClickListener和onListItemClick事件的分别响应

     5.继承ListActivity的布局文件中如果有ListView的话,其ID应该为 ”@android:id/list”,如果你不定义成这样,这个 ListView 是不能被 ListActivity 识别的

ListView和Adapter

 

ListView和Adapter

 

 

 

posted on 2012-07-30 12:33 adm1989 阅读(...) 评论(...) 编辑 收藏

相关文章:

  • 2021-08-09
  • 2021-11-22
  • 2021-12-05
  • 2021-12-05
  • 2021-11-09
  • 2017-12-06
  • 2021-11-30
  • 2021-12-05
猜你喜欢
  • 2021-11-20
  • 2021-11-30
  • 2021-11-02
  • 2019-01-04
  • 2018-12-31
  • 2021-05-17
  • 2021-11-02
  • 2021-12-05
相关资源
相似解决方案