如何在对话框中显示String类型的Arraylist

时间:2011-05-17 08:19:11

标签: android

我有一个String类型的Arraylist。如何在用户的对话框中显示它并选择一个用户。还需要突出显示用户所做的早期选择。 一些代码示例将很有帮助。 感谢

1 个答案:

答案 0 :(得分:0)

在你的onCreate

中试试这段代码
protected CharSequence[] Months = { "January", "February", "March", "April", "May","June", "July", "August", "September","October","November","December" };
Button selected_month = ( Button ) findViewById( R.id.button );
selected_month.setOnClickListener(new View.OnClickListener(){
                       new AlertDialog.Builder( <Classname>.this )
                  .setTitle( "Months" )
                      .setSingleChoiceItems( Months, 0, new DialogInterface.OnClickListener(){

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                Toast.makeText(<Classname>.this, Months[which], Toast.LENGTH_SHORT).show();
            }

        })
        .setPositiveButton( "OK", new DialogButtonClickHandler() )
        .setNegativeButton("No", new DialogButtonClickHandler() )
        .create();
});