方法 putStringExtra(String, String) 对于类型 Intent 是未定义的 [英] The method putStringExtra(String, String) is undefined for the type Intent

查看:41
本文介绍了方法 putStringExtra(String, String) 对于类型 Intent 是未定义的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决一个我不明白的问题.我在 onItemClick 方法的第 4 行中收到错误未定义类型 Intent 的方法 putStringExtra(String, String)".这可能是什么原因?

I am trying to fix an issue I do not understand. I get an error "The method putStringExtra(String, String) is undefined for the type Intent" in line 4 inside my onItemClick method. What could be the reason for this?

public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3)
{
    String item=adapter.getItemAtPosition(position).toString();
    Toast.makeText(Activity.this, "You Click on:"+item, Toast.LENGTH_SHORT).show();
    Intent intent = new Intent(this, MyOtherActivity.class);
    intent.putStringExtra(MyOtherActivity.TEXT_TO_DISPLAY, item);
    startActivity(intent);
}

推荐答案

只需使用 Intent.putExtra().Intent 上没有方法 putStringExtra().它知道参数的类型是什么并添加额外的类型.

Just use Intent.putExtra(). There is no method putStringExtra() on Intent. It knows what the type of the parameter is and adds the extra with its type.

这篇关于方法 putStringExtra(String, String) 对于类型 Intent 是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆