ListView
通常当我在简单的 ArrayAdapter 中创建一个。它无需额外设置即可自动获得此突出显示功能。但是,当我ListView
使用自定义创建此功能时,CursorAdapter
此功能似乎丢失了,我找不到解决方法。
这是我的自定义 CursorAdapter public class RecentCallAdapter extends CursorAdapter {
private final String tag = this.getClass().getSimpleName();
public RecentCallAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
// TODO Auto-generated constructor stub
}
private static class ViewHolder {
TextView name;
TextView date;
int nameCol;
int dateCol;
int numberCol;
Calendar cal;
}
@Override
public void bindView(View v, Context context, Cursor cursor) {
// TODO Auto-generated method stub
ViewHolder holder = (ViewHolder) v.getTag();
if (holder == null) {
holder = new ViewHolder();
holder.name = (TextView) v.findViewById(R.id.recentcall_item_name);
holder.date = (TextView) v.findViewById(R.id.recentcall_item_date);
holder.nameCol = cursor.getColumnIndex(Calls.CACHED_NAME);
holder.dateCol = cursor.getColumnIndex(Calls.DATE);
holder.numberCol = cursor.getColumnIndex(Calls.NUMBER);
holder.cal = Calendar.getInstance();
v.setTag(holder);
}
String name = cursor.getString(holder.nameCol);
if(name == null){
name = cursor.getString(holder.numberCol);
}
holder.name.setText(name);
holder.cal.setTimeInMillis(Long.valueOf(cursor.getString(holder.dateCol)));
holder.date.setText(Utility.calculateTimePass(holder.cal.getTime()));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.recentcall_item, parent, false);
bindView(v, context, cursor);
return v;
}
有什么办法可以解决这个问题?谢谢。