I have a listview
which contains TextView
and ImageView
.
Here it is:
OnClick
of ImageView
changes opens an alertdialog
with buttons Yes and No.
if press Yes
imageView
changes its background to blue,
if press no,
imageView
background changes to red.
Till now it is working fine.
I have a search edittext
above the listview
, which searches based on the textview
in the listview
.
Now on searching, the imageview
is not showing the changed background, but the default background only. See this:
What should I do to make the imageview
show the image which was selected in the alert dialog.
Code
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.custom_lay, null);
}else{
v=convertView;
}
holder = new ViewHolder();
holder.code = (TextView) v.findViewById(R.id.DealerName);
holder.btnName = (ImageView) v.findViewById(R.id.BtnStreet);
holder.btnName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View vi) {
// TODO Auto-generated method stub
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("select any one?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// holder.btnName.setBackgroundResource(R.drawable.green_icon);
vi.setBackgroundResource(R.drawable.blue_icon);
// notifyDataSetChanged();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
holder.btnName.setImageResource(R.drawable.blue_icon);
//vi.setBackgroundResource(R.drawable.green_icon);
// notifyDataSetChanged();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
v.setTag(holder);
ViewHolder hold = (ViewHolder) v.getTag();
String lb = DisplayedValues.get(position);
hold.code.setText(getItem(position));
// hold.btnName.setBackgroundResource(getSelectedItemPosition());
return v;
}