[英]putExtra String Intent Android
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
m = lv.getAdapter().getItem(info.position).toString();
Toast.makeText(getBaseContext(), "You clicked !"+m, Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to delete this Fixture?");
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//listAdapter.remove(m);
Intent i = new Intent(Afc.this.getApplicationContext(), WebViewExample.class);
i.putExtra("Key", m);
startActivity(i);
}
//new class activity WebView///////////// //新课程活动WebView /////////////
Bundle extras = getIntent().getExtras();
String addOn = extras.getStringExtra("key",m);
Toast.makeText(getBaseContext(), "You clicked !"+addOn, Toast.LENGTH_SHORT).show();
Hi I am passing a string with an intent, its giving me a error in the new activity on the variable m, inside the getStringExtra("key",m);. 嗨我传递一个带有意图的字符串,它在变量m的新活动中给出了一个错误,在getStringExtra(“key”,m);中。 can anyone help? 有人可以帮忙吗?
Am I doing this the right way? 我这样做是对的吗?
The key of putExtra is case sensitive. putExtra的关键是区分大小写。 One time you use 有一次你使用
key 键
and in the another 在另一个
Key 键
You should use key or Key in both cases. 在这两种情况下都应该使用密钥或密钥。
In any case use getStringExtra("key") instead of getStringExtra("key", m). 在任何情况下都使用getStringExtra(“key”)而不是getStringExtra(“key”,m)。 As you can see in the d ocumentation there isn't a getStringExtra method that takes two parameters. 正如您在d ocumentation中所看到的,没有getStringExtra方法接受两个参数。 To explain: your variable m can't be resolved because you just declared it in your first class but not in the second. 解释一下:你的变量m无法解析,因为你刚刚在第一个类中声明了它,而在第二个类中没有声明。
Yes and getStringExtra("key",m);??? 是和getStringExtra(“key”,m); ??? is Wrong USE getStringExtra("key") ; 是错误的USE getStringExtra(“key”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.