I'm using a ListFragment with a custom Adapter.
My adapter have a textview
and a hide imageview
with a arrow. When user select a item, the arrows shows up and the background color change. But, when user scroll the list, all the changes get back to default.
What I should do to fix the changes?
EDIT:
my Adapter class..
public class PropriedadeAdapter extends BaseAdapter {
private Context context;
private List<Propriedades> prop;
public PropriedadeAdapter(Context context, List<Propriedades> prop) {
this.context = context;
this.prop = prop;
}
public int getCount() {
return prop.size();
}
public Object getItem(int position) {
return prop.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// Recupera o produto da posição atual
Propriedades p = prop.get(position);
// Layout XML
int arquivoLayout = R.layout.lista_prop;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(arquivoLayout, null);
// Atualiza o valor do Text para o nome do produto
TextView textNome = (TextView) v.findViewById(R.id.nome);
textNome.setText(p.getNome());
return v;
}
}
my Fragment class..
public class frag_lista extends ListFragment{
ImageView ultimoItem = null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayList<Propriedades> props = new ArrayList<Propriedades>();
for(int i = 0; i <50; i++)
{
Propriedades prop = new Propriedades();
prop.setNome("FRUTA "+i);
props.add(prop);
}
setListAdapter(new PropriedadeAdapter(this.getActivity(),props));
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
ImageView seta = (ImageView)v.findViewById(R.id.imgSeta);
seta.setVisibility(0);
LinearLayout linha = (LinearLayout)v.findViewById(R.id.linha);
linha.setBackgroundColor(Color.GRAY);
if(ultimoItem != null)
{
ultimoItem.setVisibility(4);
}
ultimoItem = seta;
}
}
what i should do to persiste the changes of onListItemClick method????