The method putStringExtra(String, String) is undefined for the type Intent

∥☆過路亽.° 提交于 2021-02-11 12:53:27

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/26399325/the-method-putstringextrastring-string-is-undefined-for-the-type-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!