【发布时间】:2015-09-08 10:15:01
【问题描述】:
我想使用 Firebase 从 ChatListAdapter 类的 mainActivity 中弹出一个警报视图。
问题/错误:
com.firebase.androidchat.Main.activity.this 不能被静态上下文引用
ChatListAdapter 中的代码:
public class ChatListAdapter extends FirebaseListAdapter<Chat> {
...
protected void populateView(View view, Chat chat) {
...
MainActivity.displayAmountPopup();
}
ChatListAdapter 中的代码:
public static void displayAmountPopup(){
....
new AlertDialog.Builder(MainActivity.this)
.setTitle(strTitle)
.setMessage(strAmountMessage)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d("AlertDialog", "Positive");
// Present Acknowledgement View!!!!!!!!!
Intent intent = new Intent(MainActivity.this, AcknowledgementActivity.class);
startActivity(intent);
/*Couldn't work this Error:local variable mContext is accessed from within inner class; needs to be declared final
Intent intent = new Intent(mContext, AcknowledgementActivity.class);
//startActivity(intent);
mContext.startActivity(new Intent(mContext, AcknowledgementActivity.class));*/
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d("AlertDialog", "Negative");
}
})
.show();
}
【问题讨论】: