关于上次ListView细节讲解
2016-02-05 16:15
288 查看
inflater是一个系统服务,一般在继承自Activity的java文件中有
1.LayoutInflater inflater = getLayoutInflater(); //调用Activity的getLayoutInflater()
2.LayoutInflater localinflater =(LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
3. LayoutInflater inflater = LayoutInflater.from(context);
作为将资源文件实例化,作为对象进行调用。
关于ListView的两个文件作用,即item_haoyou.xml,以及fragment_haoyou.xml,这里是适配器,即一个作为主界面显示,另一个作为主界面里面每一个小界面的显示,有四种方法
1)自定义适配器
personListView.setAdapter(new MyListAdapter());//自实现BaseAdapter
2)SimpleAdapter
List<Map<String, String>> data = new ArrayList<Map<String, String>>();
for (Person p : persons) {
Map<String, String> datavalue = new HashMap<String, String>();
datavalue.put("name", p.getName());
datavalue.put("age", p.getAge().toString());
data.add(datavalue);
}
personListView.setAdapter(new SimpleAdapter(this, data, R.layout.item, new String[]{"name", "age"}, new int[]{R.id.tv_name, R.id.tv_age}));
3)arrayAdapter
public ArrayAdapter(android.content.Context context, int resource, int textViewResourceId, T[] objects) { throw new RuntimeException("Stub!"); }
String[] personArray = new String[persons.size()];
for(int i=0;i<persons.size();i++){
personArray[i] = persons.get(i).getName();
}
personListView.setAdapter(new ArrayAdapter(this,R.layout.item,R.id.tv_name,personArray));
4)simpleCursorAdapter
可以见得我使用的最简单的做法,另外我还加了一些滚动以及点击的处理
1.LayoutInflater inflater = getLayoutInflater(); //调用Activity的getLayoutInflater()
2.LayoutInflater localinflater =(LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
3. LayoutInflater inflater = LayoutInflater.from(context);
作为将资源文件实例化,作为对象进行调用。
关于ListView的两个文件作用,即item_haoyou.xml,以及fragment_haoyou.xml,这里是适配器,即一个作为主界面显示,另一个作为主界面里面每一个小界面的显示,有四种方法
1)自定义适配器
personListView.setAdapter(new MyListAdapter());//自实现BaseAdapter
2)SimpleAdapter
List<Map<String, String>> data = new ArrayList<Map<String, String>>();
for (Person p : persons) {
Map<String, String> datavalue = new HashMap<String, String>();
datavalue.put("name", p.getName());
datavalue.put("age", p.getAge().toString());
data.add(datavalue);
}
personListView.setAdapter(new SimpleAdapter(this, data, R.layout.item, new String[]{"name", "age"}, new int[]{R.id.tv_name, R.id.tv_age}));
3)arrayAdapter
public ArrayAdapter(android.content.Context context, int resource, int textViewResourceId, T[] objects) { throw new RuntimeException("Stub!"); }
String[] personArray = new String[persons.size()];
for(int i=0;i<persons.size();i++){
personArray[i] = persons.get(i).getName();
}
personListView.setAdapter(new ArrayAdapter(this,R.layout.item,R.id.tv_name,personArray));
4)simpleCursorAdapter
可以见得我使用的最简单的做法,另外我还加了一些滚动以及点击的处理
相关文章推荐
- 2016蓝桥杯历届试题——核桃的数量(最小公倍数)
- strcpy 溢出问题
- API调用
- 电脑9针串口
- 一些很少用到的js
- 下载、安装jdk8(Windows下)并配置变量环境
- char、varchar、nchar、nvarchar特点比较
- js全局变量和局部变量
- spring aop自动代理注解配置失效问题及原理机制整理总结
- 1设计模式实战沙盘系列
- 《C语言程序设计》指针篇<二>
- C# 串口通信程序
- BZOJ-1861 Book 书架 Splay
- Servlet知识总结
- unity3d下用wikitude sdk开发图片识别的AR
- MFMailComposeViewController in iOS 7 statusbar are black
- BZOJ-1861 Book 书架 Splay
- VC++建立动态库
- Type 'jint' could not be resolved, and JNIEnv, jclass
- SharePoint2016 New Feature (Preview) - SMTP Server Improvement