0
我试图创建一个简单的警报对话,我下面从这个link 的步骤不过,我得到的错误:getActivity() can't be resolved
一些搜索我了解,getActivity()
可由用户定义之后,但我不知道我该怎么做。警报对话
以下是我有:
public void about(View v1) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Add the buttons
builder.setNeutralButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();//go to the previous activity
}
});
// Set other dialog properties
builder.setMessage(R.string.myName);
// Create the AlertDialog
AlertDialog dialog = builder.create();}
- 有什么不对的这种做法?
- 有什么其他更好的方法可以建议吗?
- 哦,应该用什么
getActivity()
?
你通常应该避免代码的答案。这有点严峻... – Badacadabra