繁体   English   中英

Intent类型的方法putExtra(String,boolean)不适用于参数(String,CarouselDataItem)

[英]The method putExtra(String, boolean) in the type Intent is not applicable for the arguments (String, CarouselDataItem)

我在日食说明中出现错误

"The method putExtra(String, boolean) in the type Intent is not applicable for the arguments (String, CarouselDataItem)"

如何避免这种情况? 我正在尝试在Android中实现图片轮播,但似乎无法避免此问题。 我尝试将docu的类型更改为boolean-但是,这只会引起更多问题。

任何建议,不胜感激。

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
         CarouselDataItem docu =  (CarouselDataItem) m_carouselAdapter.getItem((int) arg3);

            Intent intent = null;

            if (docu .equals("John F. Kennedy"))
                intent = new Intent (MainActivity.this, Audio.class);
            if (docu .equals("Lyndon B. Johnson"))
                intent = new Intent (MainActivity.this, Video.class);
            if (docu .equals("Richard Nixon"))
                intent = new Intent (MainActivity.this, Photos.class);
            if (docu .equals("Gerald Ford"))
                intent = new Intent (MainActivity.this, Written.class); 
            if (intent != null) {
                intent.putExtra("KEY", docu );
                startActivity(intent);
            }
        };

    public void onNothingSelected(AdapterView<?> arg0) {}

}

任何建议,不胜感激。

您正在尝试通过活动传递自定义对象。 在这种情况下,要在“活动”之间传递的任何类型的对象都必须实现ParcelableSerializable接口。

可序列化更易于实现,但官方建议使用可打包。 您可以在此线程中找到更多信息。

您不能使用docu调用putExtra,因为docu的类型为CarouselDataItem,并且Intent中不存在名为putExtra且参数为String和CarouseldataItem的方法。 相反,让CarouselDataItem扩展Parcelable,使它能够在活动之间发送。

有关良好的示例,请参见有关可包裹的博客文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM