大家好我有3列Sqlite数据库到ListView
。如果给定的日期在当前日期之前,我试图将员工DOB(TextView
)颜色的empDobTxt
更改为红色。
我跟随this tutorial。
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.empIdTxt = (TextView) convertView
.findViewById(R.id.txt_emp_id);
holder.empNameTxt = (TextView) convertView
.findViewById(R.id.txt_emp_name);
holder.empDobTxt = (TextView) convertView
.findViewById(R.id.txt_emp_dob);
holder.empSalaryTxt = (TextView) convertView
.findViewById(R.id.txt_emp_salary);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Employee employee = (Employee) getItem(position);
holder.empIdTxt.setText(employee.getId() + "");
holder.empNameTxt.setText(employee.getName());
holder.empSalaryTxt.setText(employee.getSalary() + "");
holder.empDobTxt.setText(formatter.format(employee.getDateOfBirth()));
String dtStart = empDobTxt.getText().toString();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
String currentDateandTime = sdf.format(new Date());
try {
Date date = sdf.parse(dtStart);
Date date1 = sdf.parse(currentDateandTime);
if(date.before(date1));
{
empDobTxt.setTextColor(Color.RED);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return convertView;
}
这是logCat
:
02-17 11:33:00.486: E/AndroidRuntime(7308): java.lang.NullPointerException
02-17 11:33:00.486: E/AndroidRuntime(7308): at com.androidopentutorials.sqlite.adapter.EmpListAdapter.getView(EmpListAdapter.java:88)
答案 0 :(得分:0)
试试这个。
Listener
答案 1 :(得分:-2)
尝试使用 jQuery("customer").select2({
query: function (options) {
alert('ok');
// my ajax call would be here
xajax_getCustomers(stringFilled);
}
});
代替String dtStart = holder.empDobTxt.getText().toString();
String dtStart = empDobTxt.getText().toString();
代替holder.empDobTxt.setTextColor(Color.RED);
此字符串还有额外的分号
empDobTxt.setTextColor(Color.RED);
这就是为什么你的所有文字都是红色的。