i want to change my listview item's Backgroundcolor but when I run it wont change and showing that index not found. here i also checked that last if(sts.equals("true")) condition is matched or not, but also it matched successfully just color is not changing, it invokes the catch part and showing "Error in fetching data: null"
public void viewTask()
{
int i=0;
try{
Cursor c1 = myDB.rawQuery("SELECT * FROM "+TBName+" where Event_id= '" +Eid+ "'" , null);
String Data[] = new String[c1.getCount()+1];
if (c1 != null) {
c1.moveToFirst();
do {
Tname = c1.getString(c1.getColumnIndex("Task_name"));
sts= c1.getString(c1.getColumnIndex("Status"));
Data[i]=Tname;
item.add(Data[i]);
if(sts.equals("true"))
{
//Toast.makeText(getApplicationContext(),"Match",Toast.LENGTH_LONG).show();
lvProlist.getChildAt(i).setBackgroundColor(Color.GREEN);
}
i++;
}while(c1.moveToNext());
}
}
catch (Exception e) {
// TODO: handle exception
if(i>0){
Toast.makeText(getBaseContext(),
"Error in Fetching data: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getBaseContext(),
"PLEASE ADD TASK", Toast.LENGTH_LONG).show();
}
}
}