Sunday, June 9, 2013

[android help] Customizing change Text and Background Color of row Item programmatically in Android


Customizing change Text and Background Color of row Item programmatically in Android


listview - Customizing change Text and Background Color of row Item programmatically in Android - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















Help me! I have already fill adapter into Listview and It works fine. My problem is how to change Text and Background color in specific row Item (using TextView) when selected.



@Override
public void onItemClick(AdapterView a, View v, int position, long id) {
int visiblePosition = listView1.getFirstVisiblePosition();
View view = (View)listView1.getChildAt(position);


..... });


But it doesn't work as well. By the way, please show me how to prevent loading data when scrolling in Listview (using custom adapter) or how to fill adapter into all row when first run. Thanks for your time!!!


























it doesn't work because the children of a listview are being re-used each time you scroll.


you should either update the data and call notifyDataSetChanged , or update the data and use something like:



int visiblePosition = mListView.getFirstVisiblePosition();
View view = mListView.getChildAt(position - visiblePosition);
if(view!=null)
{
// update the view to have a different background and other stuff...
}


notes about the second way:























default






.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...