I'm new in android .I'm working with gallary.I would like to know how to save previous button state when I click on next gallery item.I want to make default button state off on all images and when button state will select with image it shoud be safe when I click on next one.When I come back on previous image it shoud be show saving button state .I tried to compare image id and button selected image id.But that's not really good work .How to do this?Thanks a lot for feature help.
imageView = (ImageView) findViewById(R.id.ImageSportView);
imageView.setImageResource(imgID[0]);
sportButton = (Button) findViewById(R.id.SportButton1);
gallery = (Gallery) findViewById(R.id.SportGallery);
// creating AddImgadapter
gallery.setAdapter(new AddImgAdapter(this));
@Override
public void onItemClick(AdapterView<?> perent, View view,
int position, long id) {
// getting id position
setSelected(position);
// deselect button on item click
onImageClick(view, position);
Log.d(MY_LOG, "img click");
Log.d(MY_LOG, "img Id" + position);
}
});
}
// deselect button on image click
int itemPosition = 1;
public void onImageClick(View button, int position) {
itemPosition = position;
if (selectedPosition != position) {
sportButton.setSelected(false);
Log.d(MY_LOG, "selected postion " + selectedPosition + " = "
+ "item position" + position);
} else {
if (selectedPosition == position) {
sportButton.setSelected(true);
}
Log.d(MY_LOG, "selected postion " + selectedPosition + " = "
+ "item position " + position);
}
}
// getting Id current item
int selectedPosition = -1;
private void setSelected(int position) {
selectedPosition = position;
imageView.setImageResource(imgID[selectedPosition]);
}
public void onClickButton(View button) {
if (button.isSelected()) {
button.setSelected(false);
Log.d(MY_LOG, "click off");
} else {
// on button click on we select picture id
button.setSelected(true);
if (selectedPosition != -1) {
Log.d(MY_LOG, "selected position " + selectedPosition);
//selectedImage(selectedPosition);
//Intent intent = new Intent(Sport.this, Favorites.class);
}
Log.d(MY_LOG, "click on");
}
}