So I have a nice little list with a cursoradapter.
After creation, I'm trying to color the rows depending on what kind of values they hold. I do it with this function below. The problem:
If I call this function from a "list.setOnItemClickListener()...", it runs perfectly.
But if I call it from my OnCreate(), I get a nullpointerexeption on my "TextView tv = (TextView) childview.findViewById(R.id.row_eszkoz_leltarozott_allapot);" row.
What causes this?
public void ConditionalColoring()
{
for (int position=0; position<adapter.getCount(); position++)
{
System.out.println("adapter child szám: " + adapter.getCount());
View childview = list.getChildAt(position);
//View childview = adapter.getView(position, null , list);
TextView tv = (TextView) childview.findViewById(R.id.row_eszkoz_leltarozott_allapot); ///ERROR HERE
RelativeLayout RL = (RelativeLayout) childview.findViewById(R.id.row_eszkoz_container);
String s = (String) tv.getText();
System.out.println("szöveg: " + s);
if (s.equals("leltárazva")) {
int holoblue = activity.getResources().getColor(android.R.color.holo_blue_light);
RL.getBackground().setColorFilter(holoblue,PorterDuff.Mode.MULTIPLY);
}
else if (s.equals("leltározandó")) {
int hologreen = activity.getResources().getColor(android.R.color.holo_blue_light);
RL.getBackground().setColorFilter(hologreen,PorterDuff.Mode.MULTIPLY);
}
else if (s.equals("módosítási tranzakció szükséges")) {
int holored = activity.getResources().getColor(android.R.color.holo_blue_light);
RL.getBackground().setColorFilter(holored,PorterDuff.Mode.MULTIPLY);
}
else {
}
}
}
In the
CursorAdapter
overridegetView()
Btw,
System.out.println()
????check this: http://developer.android.com/reference/android/util/Log.html