1.public class UserListAdapter extends ArrayAdapter<User> {  
2.    private int resourceId;  
3.    public UserListAdapter(Context context, int textViewResourceId, List<User> objects) {  
4.        super(context, textViewResourceId, objects);  
5.        this.resourceId = textViewResourceId;  
6.    }  
7.      
8.    @Override  
9.    public View getView(int position, View convertView, ViewGroup parent){  
10.        User user = getItem(position);  
11.        LinearLayout userListItem = new LinearLayout(getContext());  
12.        String inflater = Context.LAYOUT_INFLATER_SERVICE;   
13.        LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);   
14.        vi.inflate(resourceId, userListItem, true);  
15.        TextView tvUsername = (TextView)userListItem.findViewById(R.id.tv_user_list_username);  
16.        TextView tvAskedNum = (TextView)userListItem.findViewById(R.id.tv_user_list_askednum);  
17.        TextView tvLastMsg = (TextView)userListItem.findViewById(R.id.tv_user_list_lastmsg);  
18.        tvUsername.setText(user.getUsername());  
19.        tvAskedNum.setText(String.valueOf(user.getAskedNum()));  
20.        tvLastMsg.setText(user.getLastMsg());  
21.        return userListItem;  
22.    }  
23.} 能给我讲讲10-14行的意思吗?android官方文档英文的看不懂啊

解决方案 »

  1.   

    getView(adapter中每行的位置,layout文件夹中资源的位置,这个不知道,貌似也没有用到这个参数)
    {
     10.获取adapter中每行的位置给user
     11.根据上下文对象创建一个linearlayout的布局对象(因为资源文件中的布局只有一个TextView)
     13.创建一个layoutInflator的对象来对linearlayout对象进行扩充,12是用到的系统参数
     14.这个方法具体不知道什么意思,但是应该是表示 将linearlayout布局对象和资源文件中的TextView进行 
         绑定之类的吧.
       //剩下的就知道了,最后就是返回这个linearlayout的布局对象
    }另外对于这个ArrayAdapter感到迷惑,它是一个泛型类ArrayAdapter<T>吗?
    我始终对这个ArrayAdapter<T>感到很迷糊,有时是ArrayAdapter<String>,不太懂啊