无法从 View 投射到 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();
}
}
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我没有尝试过类似的操作,但我会尝试检查 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.
我也有同样的问题。
确保您的类名称不是 ViewFlipper
I had the same problem.
Make sure your class name is not ViewFlipper
确保您的类名不是 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);