【问题标题】:problem in loading image on clicking back button单击后退按钮时加载图像的问题
【发布时间】:2010-11-17 06:35:00
【问题描述】:

hii,在我的 android 应用程序中,drawable 文件夹中有许多图像。在我的布局中有两个按钮: 后退和前进按钮。单击下一个和后退按钮时,不同的 2 图像会加载到相同的布局上(所有图像通用)。 问题:我可以在下一个/后退按钮单击时加载图像,但是在到达最后一个图像后,我想让我的下一个按钮单击禁用,并且后退按钮相同。因为用户在第一张图片后退按钮将被禁用。代码如下:

public class SequencerActivity extends Activity implements OnClickListener

{ 私有 int imageCounter = 0; 私有 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**
            }
        }
        break;
    }
    this.loadImage(imagePath);

}

private void loadImage(int imagePath)
{
    imageLoader.setImageResource(imagePath);

}

}

请帮忙。谢谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    当你有 onClick 事件时你忘记减少你的计数器

    case R.id.back:
            if(imageCounter > 0)
            {
                imageCounter --;
                imagePath = imageList[imageCounter];
            }
            break;
        }
    

    否则你总是加载相同的图像

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 2018-02-16
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      • 2015-10-11
      相关资源
      最近更新 更多