Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获取ViewFlipper';当前的子位置_Android - Fatal编程技术网

Android 如何获取ViewFlipper';当前的子位置

Android 如何获取ViewFlipper';当前的子位置,android,Android,我已经向ViewFlipper添加了一组图像,现在我正在flipper中执行onClick事件。为此,我想知道当前子对象的位置,以便在数组中执行一些操作。是否还有其他方法可以找到当前子对象的位置 使用indexOfChild() 查看此帖子 希望这对您有用。使用此选项获取当前子位置: flipper.getDisplayedChild(); 此选项用于设置要查看的子编号: flipper.setDisplayedChild(8); 在addflipperimages(ViewFlipper

我已经向ViewFlipper添加了一组图像,现在我正在flipper中执行onClick事件。为此,我想知道当前子对象的位置,以便在数组中执行一些操作。是否还有其他方法可以找到当前子对象的位置

使用indexOfChild()

查看此帖子


希望这对您有用。

使用此选项获取当前子位置:

flipper.getDisplayedChild();
此选项用于设置要查看的子编号:

flipper.setDisplayedChild(8);
addflipperimages(ViewFlipper-flipper)
方法中,您正在为正在创建的imageview向ViewFlipper添加一组图像,将标记设置为imageview,将imageview clickable设置为true,然后将onclick方法写入imageview。浏览休闲代码,它可能对您有效
这里的
ids[]
是一个图像id数组

private void addFlipperImages(ViewFlipper flipper) {

        int imageCount = ids.length;
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT,
            RelativeLayout.LayoutParams.FILL_PARENT);

    for (int count = 0; count <imageCount; count++) {
        ImageView imageView = new ImageView(this);
        Bitmap imbm = BitmapFactory.decodeResource(this.getResources(),ids[count]);          
        imageView.setImageBitmap(imbm);

        imageView.setLayoutParams(params);
        imageView.setTag(count);
        imageView.setClickable(true);

        imageView.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                int id=(Integer) v.getTag();
                Toast.makeText(ImageSliderVertical.this, id+"", Toast.LENGTH_LONG).show();

            }
        });
        flipper.addView(imageView);
        flipper.setTag(count);

                  }

}
private void addFlipperImage(ViewFlipper-flipper){
int imageCount=ids.length;
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL\u父级,
RelativeLayout.LayoutParams.FILL\u PARENT);

对于(int count=0;count我使用了这个
flipper.indexOfChild(flipper.getCurrentView())

听上去不错。:)