android笔记

来源:互联网 发布:python 量化分析 编辑:程序博客网 时间:2024/06/18 04:56


ListView 
列表的显示需要三个元素:


1.ListVeiw 用来展示列表的View。


2.适配器 用来把数据映射到ListView上的中介。


3.数据    具体的将被映射的字符串,图片,或者基本组件。


根据列表的适配器类型,列表分为三种,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter


其中以ArrayAdapter最为简单,只能展示一行字。SimpleAdapter有最好的扩充性,可以自定义出各种效果。


SimpleCursorAdapter可以认为是SimpleAdapter对数据库的简单结合,可以方面的把数据库的内容以列表的形式展示出来。


获取通讯录列表
Cursor cursor = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
startManagingCursor(cursor);

AndroidManifest.xml加配置
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>


例子:
listView = new ListView(this);
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,getData()));
        setContentView(listView);


参数传递与返回结果


四种方式:
1.intent
2.静态变量
3.剪切板   复制粘贴
4.全局变量(只要不清内存就存在)  相当于java的application(只要server不停就能访问到),java web 四个作用域 小到大:page request session application


LayoutInflater类:
LayoutInflater 它的作用类似于findViewById(),不同在于findViewById去的是R.layout.xml文件中的控件,如Button、textView
而LayoutInflater取的是r.layout.xml本身
具体作用:
1、对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来载入;
2、对于一个已经载入的界面,就可以使用Activiyt.findViewById()方法来获得其中的界面元素。
获得 LayoutInflater 实例的三种方式
1. getLayoutInflater();//调用Activity的getLayoutInflater() 
2. LayoutInflater.from(context);  
3. (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
0 0
原创粉丝点击