Custom Listview Index automatically changes
<p>I've listview on which when a user clicks an item I show an image that user has clicked this item.The listview gets populated from notifications.</p>

<p>Suppose an item gets added in listview.Now I click that item and image is shown in front of it.Now when I enter the new item in the listview nothing will happen(there are 2 items in the listview now). When I add the third item in the listview the image from the item at position 0  hides and is shown in position 1. Why this is happening? </p>

<p>Now to add an image in the listview item. I have to first perform some checks on the next opening activity and if those checks are successful then I place an image in front of that clicked item in the activity.</p>

<p>So to do this what i did is I am sending the clicked item position in the next activity and perform those checks, if those checks are successful I place and image on the <code>onActivityResult</code> function of the previous activity by using that position which I sent to this activity.Meaning that I send that position value back to the previous activity in the <code>onActivityResult</code> function where I place the Image.</p>

<p>The placement of image works fine.But while I recieve notification I add the item in the listview which results in the <code>getView</code> function being called for each item in the listview again to populate the listview.Here the problem occurs i.e the image from the position 0 item in the list goes to the position 1 item.</p>

<p>Please ask if more explanation is needed or something is not clear.</p>

<p>Here's the code for listview Item Click:</p>

<pre><code>                   TextView tv=(TextView)view.findViewById(R.id.clientip);

                    Intent i=new Intent(getApplicationContext(),ChatPageActivity.class);
                    i.putExtra("AdminEmail",ClientListActivity.AdminEmail);
                    i.putExtra("ClientIp",tv.getText().toString());
                    i.putExtra("ChildAt", position);

                    startActivityForResult(i, 200);
</code></pre>

<p><code>ChildAt</code> is the position I am sending.
After performing checks in the next activity.</p>

<pre><code>@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
    try {
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode!= 23)
    {   
        Integer integer=data.getExtras().getInt("ChildAt");
        ImageView imageView=(ImageView)lv.getChildAt(integer).findViewById(R.id.onlineImg);
        imageView.setImageResource(R.drawable.online);
    }

}catch(Exception e)
{
    Log.e("ClientList_onActivityResult",e.getMessage());
}

}
</code></pre>

<p>This is the <code>onActivityResult</code> if the code is not equal to 23 it means all the checks in the next activity are correct and you can place the image at the position which is sent back again to this activity from the next activity.</p>

<p>Here's the <code>getView</code> code of my BaseAdapter class:</p>

<pre><code>@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View view=convertView;

    if(convertView==null)
        view=inflater.inflate(R.layout.activeclientlist,null);

    TextView ip=(TextView)view.findViewById(R.id.clientip);

    String clientip=this.iplist.get(position);

    ip.setText(clientip);


    return view;
}
</code></pre>

<p>In the <code>baseADapter</code> I insert item in existing listview using this piece of code..</p>

<pre><code>    this.iplist.add(ip);
    this.notifyDataSetChanged();
</code></pre>

<p><strong>Important:</strong><br/>
Also I wanted to mention that this behaviour happens in a pattern i.e as i've told above the image position changes when i insert the third item.After that it changes again when I'll add the fifth item and so on.</p>
