0

我需要一些帮助才能AlertDialog从我的应用程序中运行。当有一些错误时它不会编译。尤其是在alertDialog.setItems(items, new DialogInterface.OnClickListener()setItems().

请看一下。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nastavenie_casu);
    // Show the Up button in the action bar.
    getActionBar().setDisplayHomeAsUpEnabled(true);

    final CharSequence[] items = {"30 minút", "45 minút", "60 minút", "75 minút", "90 minút"};

    Button tlacidlo = (Button) findViewById(R.id.spusti);
    EditText pripomienka = (EditText) findViewById(R.id.upozornit_za);

    pripomienka.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            // Intent myIntent = new Intent(view.getContext(), agones.class);
            // startActivityForResult(myIntent, 0);

            AlertDialog alertDialog = new AlertDialog.Builder(NastavenieCasu.this).create(); //Read Update
            alertDialog.setTitle("hi");
            alertDialog.setItems(items, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    // do something
                }

                alertDialog.show();  
            });
        }
    }
}
4

1 回答 1

0

setItems()是 AlertDialog.Builder 类的一部分,而不是 AlertDialog。尝试:

AlertDialog.Builder builder = new AlertDialog.Builder(NastavenieCasu.this); 
builder.setTitle("hi");
builder.setItems(items, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        // 
        // do something
    }

AlertDialog alertDialog = builder.create();
alertDialog.show();  
于 2013-03-08T00:13:35.603 回答