zoukankan      html  css  js  c++  java
  • 自定义ArrayAdapter示例

    主要步骤

    1、编写ToDoItem类,重写其toString方法

    2、写一个子类继承于ArrayAdapter<ToDoItem>重写其public View getView(int position, View convertView,ViewGroup parent)方法用于返回每一项的View

    @Override
        
    public View getView(int position, View convertView,ViewGroup parent){
            LinearLayout todoView;
            ToDoItem item
    =getItem(position);
            String taskString
    =item.getTask();
            Date createDate
    =item.getCreated();
            SimpleDateFormat sdf
    =new SimpleDateFormat("dd/MM/yy");
            String dateString
    =sdf.format(createDate);
            
    if(convertView==null){//如果convertView为空则重新填充一下
                todoView=new LinearLayout(getContext());
                String inflater
    =Context.LAYOUT_INFLATER_SERVICE;
                LayoutInflater vi
    =(LayoutInflater)getContext().getSystemService(inflater);
                vi.inflate(resourceId, todoView, 
    true);
            }
    else{
                todoView
    =(LinearLayout)convertView;
            }
            TextView dateView
    =(TextView)todoView.findViewById(R.id.rowDate);
            TextView taskView
    =(TextView)todoView.findViewById(R.id.row);
            dateView.setText(dateString);
            taskView.setText(taskString);
            
            
    return todoView;
        }

    代码如下:/Files/cappuccino/Todo_ListForCustomArrayAdapter.rar

  • 相关阅读:
    LVDS汇总
    smtp模块+Gmail搭建邮件发送功能
    网站建立(杂)
    xampp部署elgg
    转xampp 访问出现New XAMPP security concept
    FPGA参考电源
    android开发环境搭建问题
    cadence仿真前电路板设置(转)
    cadence串扰仿真 (转)
    cadence约束管理器总体设置 (转)
  • 原文地址:https://www.cnblogs.com/cappuccino/p/2146068.html
Copyright © 2011-2022 走看看