I would suggest modifying the OnClickListener
to just record the selected row, then call notifyDataSetChanged()
. This will cause the ListView to redraw its items by calling the adapter. Therefore, you just need to check this value in getView()
to determine whether the "colorful" view should be visible or not.
So the updated code would be something like:
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
final View v = super.getView(position, convertView, parent);
TextView myname=(TextView)v.findViewById(R.id.textView1);
TextView mydes=(TextView)v.findViewById(R.id.textView2);
TextView mytopic=(TextView)v.findViewById(R.id.textView3);
ImageView edit=(ImageView)v.findViewById(R.id.ImageView03);
RelativeLayout r = (RelativeLayout)v.findViewById(R.id.colorful)
r.setVisibility(position == positionThatSaysHi ? View.VISIBLE : View.GONE);
sent.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
positionThatSaysHi = arg2;
notifyDataSetChanged();
}
});
}
That way, you ensure that only one view will be highlighted (while also simplifying your code).