Listview with search and onclick doesnt get the right position when clicked after the filter
<p>So here's my code. I put the topic name, topic codes, and topic results in an arraylist. The problem is, for example i have A (Position 0), B (Position 1),and  C (Position 2). When I search for B and clicked it, the app will go to Position 0 which is for A. </p>

<pre><code>@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_c);

    ctopics = (ListView) findViewById(R.id.clistView);
    csearch = (EditText) findViewById(R.id.CSearch);

    ctitle = new ArrayList&lt;Ctitle&gt;();



    ctopics.setAdapter(cAdapter);
    ctitle.add(new Ctitle("Swap Two Numbers",
            "#include &lt;iostream&gt;\nusing namespace std;\nint main(){\nint a = 5, b = 10, temp;\ncout &lt;&lt; ''Before swapping.'' &lt;&lt; endl;\ncout &lt;&lt; ''a = '' &lt;&lt; a &lt;&lt; '', b = '' &lt;&lt; b &lt;&lt; endl;\n\ntemp = a;\na = b;\nb = temp;\n\ncout &lt;&lt; ''\nAfter swapping.'' &lt;&lt; endl;\ncout &lt;&lt; ''a = '' &lt;&lt; a &lt;&lt; '', b = '' &lt;&lt; b &lt;&lt; endl;\n\nreturn 0;\n}",
            "Before swapping.\na = 5, b = 10\n\nAfter swapping.\na = 10, b = 5"));
    ctitle.add(new Ctitle("While Loop",
            "#include &lt;iostream&gt;\nusing namespace std;\nint main(){\nint a = 10;\nwhile( a &lt; 15 ){\ncout &lt;&lt; ''value of a: '' &lt;&lt; a &lt;&lt; endl;\na++;\n}\nreturn 0;\n",
            "value of a: 10\nvalue of a: 11\nvalue of a: 12\nvalue of a: 13\nvalue of a: 14"));


    ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;();

    for (int i=0; i&lt;ctitle.size(); i++)
    {
        names.add(ctitle.get(i).getTopic());
    }

    cAdapter = new ArrayAdapter&lt;String&gt;(CActivity.this, android.R.layout.simple_list_item_1, names);
    ctopics.setAdapter(cAdapter);



    ctopics.setOnItemClickListener(new OnItemClickListener() 
    {

        @Override
        public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) 
        {
            Intent intent = new Intent(CActivity.this, Cdisplay.class);
            intent.putExtra("info", ctitle.get(position));
            startActivityForResult(intent, 0);

        }

    });
</code></pre>

<p>Any help would be much appreciated, thank you!</p>

<p>Edit:</p>

<p>public class Ctitle implements Serializable {</p>

<pre><code>/**
 * 
 */
private static final long serialVersionUID = 1L;

private String topic,code,result;

public Ctitle(String topic,String code,String result)
{
    super();
    this.topic=topic;
    this.code=code;
    this.result=result;

}

public String getTopic() {
    return topic;
}

public void setTopic(String topic) {
    this.topic = topic;
}

public String getCode() {
    return code;
}

public void setCode(String code) {
    this.code = code;
}

public String getResult() {
    return result;
}



public void setResult(String result) {
    this.result = result;
}
</code></pre>

<p>}</p>