hii, in my android application there are number of images in drawable folder. in my layout two buttons: back and forward button.on clicking next and back buttons different-2 image get loaded on the same layout(common for all images). Problem:i am able to load images in next/back button click but after reaching to the last image i want to make my next button click disable and same for the back button.As the user is on the first image the back button would be disable .Code is as:
public class SequencerActivity extends Activity implements OnClickListener
{ private int imageCounter = 0; private ImageView imageLoader;
private int[] imageList = {R.drawable.image_wo_lbl_0, R.drawable.image_wo_lbl_1, R.drawable.image_wo_lbl_2, R.drawable.image_wo_lbl_3, R.drawable.image_wo_lbl_4, R.drawable.image_wo_lbl_5,
R.drawable.image_wo_lbl_6, R.drawable.image_wo_lbl_8, R.drawable.image_wo_lbl_9,R.drawable.image_wo_lbl_10, R.drawable.image_wo_lbl_11};
@Override
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.parent_frame);//this one is the common parent layout for all image views
super.onCreate(savedInstanceState);
/*requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
//int image1 = R.drawable.image_w_lbl_0;
imageLoader = (ImageView) findViewById(R.id.imageLoader);
//imageLoader.setImageResource(image1);
ImageButton next = (ImageButton) findViewById(R.id.next);
ImageButton back = (ImageButton) findViewById(R.id.back);
next.setOnClickListener(this);
back.setOnClickListener(this);
//show the default image
this.loadImage(imageList[imageCounter]);
}
@Override
public void onClick(View v)
{
int imagePath = 0;
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.next:
Log.i("Tag","tag");
if(imageCounter < imageList.length)
{
imageCounter++;
imagePath = imageList[imageCounter];
if (imageCounter==(imageList.length)-1)
{
//**how to make my next button disable for last image**
}
}
break;
case R.id.back:
if(imageCounter > 0)
{
imageCounter--;
imagePath = imageList[imageCounter];
if (imageCounter==0)
{
//**how to make my back button disable for 1st image**
}
开发者_StackOverflow中文版 }
break;
}
this.loadImage(imagePath);
}
private void loadImage(int imagePath)
{
imageLoader.setImageResource(imagePath);
}
}
help please.Thanks.
when you have the onClick event for back your forgetting to decrement your counter
case R.id.back:
if(imageCounter > 0)
{
imageCounter --;
imagePath = imageList[imageCounter];
}
break;
}
without that your always loading the same image
精彩评论