谁能帮我解释这段代码 虽然会很难 还请大家帮帮忙

感觉在继续 2012-05-23 12:32:13
/**
*
*/
package com.android.FileBrowser;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
* @author zhuch
*
*/
public class FileAdapter extends BaseAdapter {

private LayoutInflater _inflater;
private List<FileInfo> _files;

public FileAdapter(Context context, List<FileInfo> files) {
_files = files;
_inflater = LayoutInflater.from(context);
}


public int getCount() {
// TODO Auto-generated method stub
return _files.size();
}


public Object getItem(int position) {
// TODO Auto-generated method stub
return _files.get(position);
}

public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}


public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;

if (convertView == null) { // convertView 可利用,如果传入为null,执行初始化操作
// 载入xml文件为View
convertView = _inflater.inflate(R.layout.file_item, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.file_name);
holder.icon = (ImageView) convertView.findViewById(R.id.file_icon);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

// 更新View信息
FileInfo f = _files.get(position);
holder.name.setText(f.Name);
holder.icon.setImageResource(f.getIconResourceId());

return convertView;
}

/* class ViewHolder */
private class ViewHolder {
TextView name;
ImageView icon;
}
}
...全文
99 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
aSysBang 2012-05-23
  • 打赏
  • 举报
回复
apidemo 多看看

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧