0
我有一個WeakReference的問題。我得到這個代碼的錯誤... 你能幫助我嗎? 我不明白如何使用WeakReference與按鈕單擊事件。WeakReference on buttonClick
public class MainActivity extends FragmentActivity {
private final WeakReference<Context> contextReference;
public MainActivity(Context context) {
this.contextReference = new WeakReference<Context>(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnArrivi.setOnClickListener(new View.OnClickListener() {
Context context = this.contextReference.get();
if(this.contextReference.get() != null) {
Intent intent = new Intent(context, Arrivi.class);
intent.putExtra("A_Compagnia", A_Compagnia);
intent.putExtra("A_CodiceVolo", A_CodiceVolo);
intent.putExtra("A_Citta", A_Citta);
intent.putExtra("A_OraPrevista", A_OraPrevista);
intent.putExtra("A_OraStimata", A_OraStimata);
intent.putExtra("thread",thread);
context.startActivity(intent);
}
}
錯誤:
contextReference cannot be resolved or is not a field
這裏:
if(this.contextReference.get() != null) {
你忘了錯誤代碼? –
張貼您的日誌貓 –
我已編輯1st post – roxdragon