在onCreateView
putExtra(dataBundle);
给出
无法解析方法'putExtra(android.os.bundle)'错误
但是
putExtra("id", id_To_Search);
工作正常。我想发送dataBunle指导我,我错过了什么。
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
int id_To_Search = position + 1;
Bundle dataBundle = new Bundle();
dataBundle.putInt("id", id_To_Search);
Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(dataBundle);
startActivity(intent);
}
答案 0 :(得分:9)
您的错误是:
方法名称是putExtras ....你缺少 s
执行:
Intent intent = new Intent(getActivity(), DetailActivity.class).putExtras(dataBundle);
另一个例子:
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putString(key, value);
mIntent.putExtras(mBundle);
答案 1 :(得分:1)
putExtra()
不返回Intent实例。所以试试吧..
Intent intent = new Intent(getActivity(), DetailActivity.class);
intent.putExtra(dataBundle);
startActivity(intent);
但你可以发送这个整数如下......
发件人方:
Intent myIntent = new Intent(getActivity(), DetailActivity.class);
myIntent.putExtra("id", id_To_Search);
startActivity(myIntent);
接收方:
Intent mIntent = getIntent();
int intValue = mIntent.getIntExtra("id", 0);