Question: I am able to setup a listview using custom adapter which shows correct output.each list item also has an gradient style see drawable.xml below how do I change the item background to some other gradient on tapping any of them. can I set different gradients for each of the items.? 

```
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
<gradient 
android:startColor="#FFFAFAFA" 
android:centerColor="#FFFFFFFF" 
android:endColor="#FFFAFAFA" 
android:angle="90"/>
</shape>

```

My files...

activity\_main.xml....Main xml file

MainActivity.java....Main activity

Item.java.... item selector method

ItemAdaptor.... custom adapter

list\_item.xml..... item (textView) styling

Answer: 
By writing your client code in terms of iterators you abstract away the container completely.

Consider this code:

```
class ExpressionParser // some generic arbitrary expression parser
{
public:
    template<typename It>
    void parse(It begin, const It end)
    {
        using namespace std;
        using namespace std::placeholders;
        for_each(begin, end, 
            bind(&ExpressionParser::process_next, this, _1);
    }
    // process next char in a stream (defined elsewhere)
    void process_next(char c);
};

```

client code:

```
ExpressionParser p;

std::string expression("SUM(A) FOR A in [1, 2, 3, 4]");
p.parse(expression.begin(), expression.end());

std::istringstream file("expression.txt");
p.parse(std::istringstream<char>(file), std::istringstream<char>());

char expr[] = "[12a^2 + 13a - 5] with a=108";
p.parse(std::begin(expr), std::end(expr));

```

Edit: Consider your original code example, implemented with :

```
using namespace std;

vector<int> myIntVector;
// Add some elements to myIntVector
myIntVector.push_back(1);
myIntVector.push_back(4);
myIntVector.push_back(8);

copy(myIntVector.begin(), myIntVector.end(), 
    std::ostream_iterator<int>(cout, " "));

```
its a matter of speed. using the iterator accesses the elements faster. a similar question was answered here:

[What's faster, iterating an STL vector with vector::iterator or with at()?](https://stackoverflow.com/questions/776624/whats-faster-iterating-an-stl-vector-with-vectoriterator-or-with-at)

Edit:
speed of access varies with each cpu and compiler