AlertDialog.Builder

时间:2012-04-25 14:53:54

标签: android button dialog android-alertdialog

所以我一直在与我的AlertDialog战斗了几个小时,现在跟着一堆不同的在线教程,没有运气。我已经成功创建了一个关闭按钮注册的对话框但我无法识别我的onClickListener下的duDialog.dismiss()或duDialog.cancel()。我确定它非常简单,但我似乎无法找出为什么它告诉我方法cancel()对于类型AlertDialog.Builder未定义dismiss()。那么如何从按钮关闭duDialog? 这是我的代码:

public void DataUsage() {
    final AlertDialog.Builder duDialog = new AlertDialog.Builder(this);

    LayoutInflater inflater = (LayoutInflater) this
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.data_usage, (ViewGroup) null);
    ListView data = (ListView) layout.findViewById(R.id.DataUsage);

    duCursor = Data.getAll(db);
    startManagingCursor(duCursor);
    duAdapter = new DataAdapter(duCursor);
    data.setAdapter(duAdapter);

    Button close = (Button) layout.findViewById(R.id.button_close);
    duDialog.setTitle("Data Usage");
    duDialog.setView(layout);
    duDialog.create();
    close.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Log.d("Button", "Close button captured");

        }
    });

    duDialog.show();
}

0 个答案:

没有答案