无法从 View 投射到 ViewFlipper

发布于 2024-10-01 03:24:40 字数 963 浏览 7 评论 0原文

你好。我已直接复制并粘贴此代码,但出现转换错误:无法从视图转换为视图翻转器。

public class ViewFlipper extends Activity implements OnClickListener 
{
    Button next;
    Button previous;
    ViewFlipper vf;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vf = (ViewFlipper) findViewById(R.id.ViewFlipper01);
        setContentView(R.layout.main);
        //vf = (ViewFlipper) findViewById(R.id.ViewFlipper01);
        next = (Button) findViewById(R.id.Button01);
        previous = (Button) findViewById(R.id.Button02);
        next.setOnClickListener(this);
        previous.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v == next) {
            vf.showNext();
        }
        if (v == previous) {
            vf.showPrevious();
        }
    }

}

Hi. I have directly copy and pasted this code but I'm getting casting error: cannot cast from view to viewflipper.

public class ViewFlipper extends Activity implements OnClickListener 
{
    Button next;
    Button previous;
    ViewFlipper vf;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vf = (ViewFlipper) findViewById(R.id.ViewFlipper01);
        setContentView(R.layout.main);
        //vf = (ViewFlipper) findViewById(R.id.ViewFlipper01);
        next = (Button) findViewById(R.id.Button01);
        previous = (Button) findViewById(R.id.Button02);
        next.setOnClickListener(this);
        previous.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if (v == next) {
            vf.showNext();
        }
        if (v == previous) {
            vf.showPrevious();
        }
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野侃 2024-10-08 03:24:40

我没有尝试过类似的操作,但我会尝试检查 ViewFlipper 不是更好的方法。

另一种选择是将所有这些作为针对移动视图进行优化的网页,您可以使用 Web 视图。这样您就可以完全控制要显示的图像数量和方式。我认为这是一个更灵活的解决方案。

I haven't tried anything similar but I'd try to checkout if the ViewFlipper isn't a better way.

Another option would be to have all that as a webpage optimized for mobile view which you load locally with a WebView. That way you get full control of how many images to display and how. It is a more flexible solution in my opinion.

泪之魂 2024-10-08 03:24:40

我也有同样的问题。
确保您的类名称不是 ViewFlipper

I had the same problem.
Make sure your class name is not ViewFlipper

残花月 2024-10-08 03:24:40

确保您的类名不是 ViewFlipper,否则使用

android.widget.ViewFlipper vf = (android.widget.ViewFlipper)findViewById(R.id.ViewFlipper01);

Make sure that your class name is not ViewFlipper otherwise use like

android.widget.ViewFlipper vf = (android.widget.ViewFlipper)findViewById(R.id.ViewFlipper01);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文