简体   繁体   English

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

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

I'm getting an error in eclipse stating 我在日食说明中出现错误

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

How might this be avoided? 如何避免这种情况? I'm attempting to implement an image carousel in Android and I cannot seem to avoid this issue. 我正在尝试在Android中实现图片轮播,但似乎无法避免此问题。 I've tried changing the type of docu to boolean - however that simply causes more issues. 我尝试将docu的类型更改为boolean-但是,这只会引起更多问题。

Any suggestions are greatly appreciated. 任何建议,不胜感激。

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) {}

}

Any suggestions are greatly appreciated. 任何建议,不胜感激。

You're attempting to pass custom Object through Activity. 您正在尝试通过活动传递自定义对象。 In this case any kind of Object that you want to pass between Activities has to implement Parcelable or Serializable interface. 在这种情况下,要在“活动”之间传递的任何类型的对象都必须实现ParcelableSerializable接口。

Serializable is easier to implement but Parcelable is officially recommended. 可序列化更易于实现,但官方建议使用可打包。 More information you can find in this thread . 您可以在此线程中找到更多信息。

You cannot call putExtra with docu, since docu is of type CarouselDataItem and there exist no method in Intent named putExtra with parameters String and CarouseldataItem. 您不能使用docu调用putExtra,因为docu的类型为CarouselDataItem,并且Intent中不存在名为putExtra且参数为String和CarouseldataItem的方法。 Instead, let CarouselDataItem extend Parcelable which enables it to be sent among activities. 相反,让CarouselDataItem扩展Parcelable,使它能够在活动之间发送。

See this blogpost about parcelable for good examples. 有关良好的示例,请参见有关可包裹的博客文章

暂无
暂无

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

相关问题 将textView转换为Boolean以避免:Intent类型中的方法putExtra(String,boolean)不适用于参数 - Converting textView to Boolean to avoid: The method putExtra(String, boolean) in the type Intent is not applicable for the arguments Integer 类型中的方法 parseInt(String) 不适用于参数(布尔值) - The method parseInt(String) in the type Integer is not applicable for the arguments (boolean) 如何修复[ContentValues类型的put(String,Boolean)方法不适用于自变量(Boolean,Boolean)] - How to fix [The method put(String, Boolean) in the type ContentValues is not applicable for the arguments (Boolean, Boolean)] 方法put(String,ArrayList <Integer> ),类型为TreeMap <String,ArrayList<Integer> &gt;不适用于参数(字符串,布尔值) - The method put(String, ArrayList<Integer>) in the type TreeMap<String,ArrayList<Integer>> is not applicable for the arguments (String, boolean) 类型“x”中的方法 getBytes() 不适用于 arguments(字符串) - The method getBytes() in the type "x" is not applicable for the arguments (String) 部分类型中的方法setText(String)不适用于参数 - method setText(String) in the type Part is not applicable for the arguments 类型为nammi的方法epli(String [])不适用于arguments() - The method epli(String[]) in the type nammi is not applicable for the arguments () 类型“ x”的方法search()不适用于参数(字符串) - The method search() in the type “x” is not applicable for the arguments (String) JsonObject类型的方法add(String,JsonElement)不适用于参数(String,String) - The method add(String, JsonElement) in the type JsonObject is not applicable for the arguments (String, String) PreparedStatement 类型中的 setString(int, String) 方法不适用于参数 (int, String[]) - The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, String[])
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM