2013-03-08 61 views
0

我需要一些幫助來從我的應用程序運行AlertDialog。在出現錯誤時它不會編譯。特別是在線alertDialog.setItems(items, new DialogInterface.OnClickListener()setItems()使用列表打開AlertDialog時出錯

請看看。

@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(); 
      }); 
     } 
    } 
} 

回答

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(); 
+0

thx男人你幫我分配 – MichalCh 2013-03-08 22:25:53