问题
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