Android:简单的适配器

public class missionStep_logs_A extends BaseAdapter implements ListAdapter {
    
    private ArrayList<missionStep_logs_C> missionStepLogsCs;
    private int id;
    private Context context;
    public missionStep_logs_A(int item, Context context, ArrayList<missionStep_logs_C> missionStepLogsCs) {
        this.missionStepLogsCs = missionStepLogsCs;

        if (context == null) {
            System.out.println("newestList_A:::" + "取为null");
        } else {
            this.context = context;
        }
        this.id = item;
    }

    @Override
    public int getCount() {
        return missionStepLogsCs.size();
    }

    @Override
    public Object getItem(int i) {
        return missionStepLogsCs.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }
    
    @SuppressLint("WrongConstant")
    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        TextView tv_create_at = null;
        if (context != null) {
            ViewHolder viewHolder;
            if (view == null) {
                view = LayoutInflater.from(context).inflate(R.layout.item_home_event, null);
                tv_create_at = (TextView) view.findViewById(R.id.tv_create_at);
                view.setTag(new ViewHolder(tv_create_at));
            } else {
                ViewHolder viewHolder1 = (ViewHolder) view.getTag(); // 重新获取ViewHolder
                tv_create_at = viewHolder1.tv_create_at;
            }
            missionStep_logs_C missionStep_logs_c = (missionStep_logs_C) missionStepLogsCs.get(i); // 获取当前项的实例
            tv_create_at.setText(missionStep_logs_c.getCreate_at().toString());
        }
            return view;
        }
        
        private final class ViewHolder {
            TextView tv_create_at = null;
            public ViewHolder(TextView tv_update_at) {
                this.tv_create_at = tv_create_at;
            }
         }
}
上一篇:基于Python的数据可视化库pyecharts介绍


下一篇:介绍Django 展示可视化图表的多种方式