主要步骤
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;
}
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;
}