在我的android应用程序中,可绘制文件夹中有多个图像。在我的布局中有两个按钮:上一个和下一个按钮。在点击下一个和后退按钮时,2个不同的图像会以相同的布局加载(所有图像都是通用的)。如何禁用按钮点击?
问题:我能够加载下一步/后退按钮的点击图片,但在到达最后一个图像后,我想我的下一个按钮禁用和同为回button.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
}
}
break;
case R.id.back:
if(imageCounter > 0)
{
imageCounter--;
imagePath = imageList[imageCounter];
if (imageCounter==0)
{
//how to make my back button disable
}
}
break;
}
this.loadImage(imagePath);
}
private void loadImage(int imagePath)
{
imageLoader.setImageResource(imagePath);
}
}
它的工作原理!!现在应用程序运行在恶心 – Alok 2010-11-18 08:51:53
kkkkkkkk它很好...... – viv 2010-11-18 09:05:49
不应该在某个时候再次启用按钮吗? – jul 2011-02-22 19:30:41