I currently have the following adapter to set up my listview:
public class MyListAdapter extends ArrayAdapter<String> {
private Context mContext;
public MyListAdapter(Context context, int resource, int textViewResourceId,String[] objects) {
super(context, resource, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Drawable cross = getResources().getDrawable(R.drawable.cross);
Drawable arrow = getResources().getDrawable(R.drawable.arrow);
View row = convertView;
if(row == null){
LayoutInflater inflater= getLayoutInflater();
row = inflater.inflate(R.layout.list_view_format2, parent, false);
}
TextView text =(TextView)row.findViewById(R.id.list_content2);
text.setText(list[position]);
ImageView image = (ImageView)row.findViewById(R.id.rightArrow);
TextView check = (TextView)row.findViewById(R.id.checker);
if (item != null && text.getText().toString().equals(item)){
text.setBackgroundDrawable(cross);
image.setImageDrawable(arrow);
check.setText("cross");
}
return row;
}
}
R.layout.list_view_format2: a custom ListView format. It contains an ImageView and a TextView R.id.list_content2: *Id of the Text View within R.id.list_view_format2*
I am trying to change certain parts of a child if the search is successful. However, instead of only one child being modified, when I scroll up or down a ListView the layout of the other children gets modified as well. I don't exactly get what is happening. Can someone please explain?