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
可以见得我使用的最简单的做法,另外我还加了一些滚动以及点击的处理