Hello i have one imageView on my view. In my activity i create in onCreate an ArrayList, where if you click on the imageView, a name will be added. So if the list contains this name, the filled star image will be loaded from the drawable folder. And here is my problem: How do i write that you click on the imageView and the other image will be load? So if theres the filled star the empty star should be loaded.
final ImageView img = (ImageView) rootView.findViewById(R.id.imageView1);
if (starredList.contains(txt1[p])){
img.setImageResource(R.drawable.ic_action_important);
}
else{
img.setImageResource(R.drawable.ic_action_not_important);
}
img.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
Object tag = img.getTag();
int id = tag == null ? -1 :(Integer) tag;
if (id==R.drawable.ic_action_important){
img.setImageResource(R.drawable.ic_action_not_important);
}
if (id==R.drawable.ic_action_not_important){
img.setImageResource(R.drawable.ic_action_important);
starredList.add(txt1[p]);
Toast.makeText(getActivity(), txt1[p]+" wurde ihren Favoriten hinzugefügt", Toast.LENGTH_LONG).show();
}
}
});
Thank you in advance!