Lea*_*ics 5 android custom-adapter
我想实现CustomArrayAdapter,以下是我为自定义适配器编写的构造函数
public CustomUsersAdapter(Context context, ArrayList<User> users) {
super(context, 0, users);
}
Run Code Online (Sandbox Code Playgroud)
超级调用中的第二个参数包含在实例化视图时使用的TextView的布局文件的资源ID.我不知道这里引用了哪个资源ID.任何人都可以详细解释这里提到的资源ID.
我重写的getView方法如下: -
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
User user = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_user, parent, false);
}
// Lookup view for data population
TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
TextView tvHome = (TextView) convertView.findViewById(R.id.tvHometown);
// Populate the data into the template view using the data object
tvName.setText(user.name);
tvHome.setText(user.hometown);
// Return the completed view to render on screen
return convertView;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
289 次 |
| 最近记录: |