2012-10-17 51 views
0

這是我的代碼的一部分。Android變量應用程序

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    IntentFilter intent = new IntentFilter(); 
    intent.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); 

    registerReceiver(searchDevices, intent); 

    private BroadcastReceiver searchDevices = new BroadcastReceiver() { 
     public void onReceive(Context context, Intent intent) { 
      String a="1"; 
     } 
    } 


    class ClickEvent implements View.OnClickListener { 
     public void onClick(View v) { 
      // here , how to get Variables in a , I can't direct use of a 
     } 
    } 
} 
+0

他寫的問題在代碼中的註釋 – Syn3sthete

回答

0

聲明爲final String a="1";

+0

即使他,我不認爲它會被onclick監聽器看到。我應該是全球性的。 –

0

String a="1"; 改變

public final String a="1"; 
0

定義一個類的成員,那麼所有的內部類,即聽衆可以訪問它。

在頂級定義

private String a; 

,然後在其他類只使用像任何其他成員變量即

a="1"; 
相關問題