我有ListView
次,我希望随着时间的推移改变ListItem
的颜色,当一天中的小时是早上8或9甚至10时,它会起作用,但随着夜晚的时间增加到5或6,它就会停止工作。他们所有的颜色都和原来一样。这很奇怪。
我知道我的代码检查小时是否已经过去了。
这是我的getView()
方法。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = activity.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_view_adapter_tab, parent, false);
holder = new ViewHolder();
SharedPreferences prefs = convertView.getContext().getSharedPreferences("com.example.edonfreiner.siddur", Context.MODE_PRIVATE);
if (prefs.getBoolean("isHebrewSet", true)) {
holder.txtSecond = (TextView) convertView.findViewById(R.id.zman);
holder.txtFirst = (TextView) convertView.findViewById(R.id.time);
} else {
holder.txtFirst = (TextView) convertView.findViewById(R.id.zman);
holder.txtSecond = (TextView) convertView.findViewById(R.id.time);
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
this.convertView = convertView;
HashMap<String, String> map = list.get(position);
holder.txtFirst.setText(map.get("First"));
holder.txtSecond.setText(map.get("Second"));
convertView.setBackgroundColor(Color.TRANSPARENT);
RelativeLayout relativeLayout = (RelativeLayout) convertView;
if (ZmanimListTab.getUpComingZmanPosition() > position) {
for (int i = 0; i < relativeLayout.getChildCount(); i++) {
((TextView) relativeLayout.getChildAt(i)).setTextColor(Color.parseColor("#77FFFFFF"));
}
}else{
for (int i = 0; i < relativeLayout.getChildCount(); i++) {
((TextView) relativeLayout.getChildAt(i)).setTextColor(Color.parseColor("#FFFFFF"));
}
}
return relativeLayout;
}
以下是获取更改颜色位置的列表索引的方法:
private void getNextAvailableZman() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
for (int i = 0; i < listZmanim.length; i++) {
Date targetDate = ((Date) complexZmanimCalendar.getClass().getMethod((String) listZmanim[i]).invoke(complexZmanimCalendar));
if (targetDate.after(now)) {
adapter.notifyDataSetChanged();
upComingZmanPosition = i;
return;
}
}
upComingZmanPosition = listZmanim.length;
}
感谢您的帮助!