Reputation: 3362
I have a listview which contains 2 textViews and an ImageView. Whenever is pressed I want to the selected row to change a bit it's layout. For example change the color of the texts change the imageView add another one etc..I have added a custom list selector for the background to change. My question is which is the correct listener in which I should add:
TextView title;
TextView descr;
title = (TextView) arg1.findViewById(R.id.title);
descr = (TextView) arg1.findViewById(R.id.descr);
title.setTextColor(Color.parseColor("#189dd9"));
descr.setTextColor(Color.WHITE);
I added it to OnItemClickListener and it works correct after the item is clicked not while it is selected.
Upvotes: 0
Views: 57
Reputation: 3362
I did using multiple selectors, according to this link I'm reposting the link just in case someone finds this thread first. cheers!
Upvotes: 0
Reputation: 17401
Inside adapter you can keep a track of which item is selected.
int selectedItemIndex;// ArrayList<Integer> selectedItems=new ArrayList<Integer>();
Now in getView just write if
if(position==selectedItemIndex){
//Inflate different layoout
}else{
//normal flow
}
To set selected items you can set onItemClick Listener and set this variable in adapter or you can add an onClick listener inside getView itself and in it set this variable.
In case you want to have same layout just write different code inside if/else
Upvotes: 1