I am using an async task and i want to change the color of each row twice,
i.e
1.I want to change the color of the row before starting my long running task
2.I want to change the color of the row after completing my long running task
Both 1.and 2. are from doinBackground.
This is my adapter:
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,al);
listView.setAdapter(arrayAdapter);
This is my async task
class AT extends AsyncTask<List<String>,Void,Void>{
@Override
protected Void doInBackground(List<String>... list) {
for(int i=0;i<n;i++){
//iterating my list , so that for every item of my list,i am performing my long running task and changing the color of rach row
final int t=i;
//trying to change the associate row color before starting my task
handler.post(new Runnable() {
@Override
public void run(){
Log.d("sri","listView.performItemClick;");
listView.performItemClick(listView.getAdapter().getView(t,null,listView),t,t);
}});
try {
Thread.sleep(5000);
Log.d("TAG","doInBackground =====> Thread.sleep(5000);");
} catch (InterruptedException e) {
e.printStackTrace();
}
//my long running task would be here
try {
Thread.sleep(3000);
Log.d("sri","doInBackground =====> Thread.sleep(3000);");
} catch (InterruptedException e) {
e.printStackTrace();
}
//trying to change the associate row color after completing my task
handler.post(new Runnable() {
@Override
public void run(){
Log.d("sri","listView.performItemClick;");
listView.performItemClick(listView.getAdapter().getView(t,null,listView),t,t);
}});
}
return null;
}}
This is onItemClick code:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.d("TAG","onItemClick --> pos is " + i + "-->id is " + l );
view.setBackgroundColor(Color.parseColor("#1234ab"));
//adapterView.getChildAt(i-adapterView.getFirstVisiblePosition()).setBackgroundColor(Color.BLUE);
Log.d("TAG","onItemClick --> pos is " + i + "-->id is " + l );
}
});
My problem is
The line *listView.performItemClick calls the OnItemClick code * (and the variable pos and id are correct ) , but view.setBackgroundColor(Color.parseColor("#1234ab")); has no effect,so the color is not changing.