2011-04-13 14 views
1
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); 
     } 

//类新活动的WebView /////////////putExtra字符串意向的Android

Bundle extras = getIntent().getExtras(); 
     String addOn = extras.getStringExtra("key",m); 
     Toast.makeText(getBaseContext(), "You clicked !"+addOn, Toast.LENGTH_SHORT).show(); 

你好我传递一个字符串的意图,它给了我一个在getStringExtra(“key”,m);内的变量m上的新活动中发生错误。谁能帮忙?

我这样做是正确的吗?

回答

4

putExtra的关键是区分大小写。有一次,你用

关键

,并在另一

主要

您应该使用在这两种情况下键,键。

在任何情况下,请使用getStringExtra(“key”)而不是getStringExtra(“key”,m)。正如你在d ocumentation中看到的,没有一个getStringExtra方法需要两个参数。解释:你的变量m不能被解析,因为你只是在第一个类中声明它,而不是在第二个类中声明它。

+1

是和getStringExtra(“key”,m); ???是错误的USE getStringExtra(“key”); – Harinder 2011-04-13 11:25:12

+1

对不起,这只是一个粘贴它的错字,错误表示“m不能解析为变量” – 2011-04-13 11:25:13

+0

感谢Harinder,这是真正的问题。我更新我的答案。 – RoflcoptrException 2011-04-13 11:26:22

0

是和getStringExtra(“key”,m); ???是错误的USE getStringExtra(“key”);