我正在玩一個簡單的應用程序,我想單擊按鈕時顯示警報。如何在點擊按鈕時獲得簡單提醒?
我到目前爲止的代碼是:
package max.helloworld.firstapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
private Button closeButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setContentView(R.layout.main);
this.closeButton = (Button)this.findViewById(R.id.close);
this.closeButton.setKeyListener(new onClickListener() {
@Override
public void onClick(View v) {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Transformers");
alertDialog.setMessage("Optimus Prime");
alertDialog.setButton("OK", new OnClickListener(){
public void onClick(DialogInterface dialog, int which){
}
});
//alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
finish();
}
});
}
}
的問題是,它說AlertDialog alertDialog =新AlertDialog.Builder(本).create();
它說構造函數是未定義的。我該如何解決這個問題?
爲什麼你叫結束之後呢?你有兩次setContentView - 爲什麼? – hovanessyan 2012-01-17 16:45:09
我刪除了那些,我正在查看各種網站的代碼,並且必須將其放入兩次。 – user1154405 2012-01-17 17:07:19