In my app i want to change the imageview in the listview on which the user click.in starting i pass the image in the listview throught the adapter class,but on click on the item i want to change the image in the imageview in listview later,how i can change the image at the particluar position.??
MainActivity
public class MainActivity extends Activity {
ListView listView;
public static int pos = 0;
String[] Prayers = new String[] { "REFLETINDO A IMAGEM DE CRISTO",
"PROVIDÊNCIA PARA TODOS OS CASOS", "A CRUZ REVELA O AMOR DE DEUS",
"REFLETINDO O AMOR DE CRISTO", "CRISTO CRUCIFICADO POR NÓS",
"AMOR IMENSURÁVEL", "DÁDIVA DO AMOR DE DEUS",
"NÃO PARA CONDENAR, MAS PARA SALVAR",
"O CENTRO DE MINHA ESPERANÇA",
};
String[] Dias = new String[] { "Dia1", "Dia2", "Dia3", "Dia4", "Dia5",
"Dia6", "Dia7", "Dia8", "Dia9", "Dia10", "Dia11", "Dia12",
"Dia13", "Dia14", "Dia15", "Dia16", "Dia17", "Dia18",
};
LinearLayout lay1 ,lay2;
int i=0;
int img ;
List<RowItem> rowItems;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
img = R.drawable.praying_hands_normal ;
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < 50; i++) {
RowItem item = new RowItem( Dias[i], Prayers[i],img);
rowItems.add(item);
}
listView = (ListView) findViewById(R.id.listview);
BaseClass adapter = new BaseClass(this, rowItems);
listView.setAdapter(adapter);
//listView.setOnItemClickListener(this);
// get the position of the clicked item
View t = null;
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
pos = position;
//Toast.makeText(getApplication(), String.valueOf(pos), Toast.LENGTH_LONG).show();
Intent i = new Intent(MainActivity.this ,OpenActivity.class);
startActivity(i);
}
});
}
Adapterclass
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list, null);
holder = new ViewHolder();
holder.txtDias = (TextView) convertView.findViewById(R.id.dias);
holder.txtPrayers = (TextView) convertView
.findViewById(R.id.prayers);
holder.imageView = (ImageView) convertView
.findViewById(R.id.symbol);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
RowItem rowItem = (RowItem) getItem(position);
holder.txtPrayers.setText(rowItem.getDesc());
holder.txtDias.setText(rowItem.getTitle());
holder.imageView.setImageResource(R.drawable.praying_hands_normal);
if(pos == position && OpenActivity.a + OpenActivity.b +
OpenActivity.c == 1 || OpenActivity.a + OpenActivity.b +
OpenActivity.c == 2)
{
holder.imageView.setImageResource(R.drawable.praying_hands_bookmark);
}
else if(pos == position && OpenActivity.a + OpenActivity.b +
OpenActivity.c == 3 )
{
holder.imageView.setImageResource(R.drawable.praying_hands_selected);
}
return convertView;
}