0

我有一个带有频道列表的警报框。

我想获得点击频道的价值。

这可能吗?

到目前为止我有这个..

  public void ShowChannelDialog(){

      String[] channels = new String[_publicChannels.size()];
      channels = _publicChannels.toArray(channels);

      AlertDialog.Builder showChannel = new AlertDialog.Builder(this);
      showChannel.setTitle("Channel List ("+(_publicChannels.size()-1)+" channels)");


      showChannel.setItems(channels, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {
            _publicChannels.clear();
            if (item == (_publicChannels.size())) {
                System.out.println("NEW CHANNEL");
                CreateNewChannel();
                dialog.dismiss();
            }else{
                String channel = String.valueOf(item);
                System.out.println("Selected: " + channel);
            }
        }
    });

String.valueof(item) 只给我数组中的 int 值,我想要实际的文本值。

谢谢!

4

3 回答 3

1

代替String.valueOf(item), 使用channels[item]. 您还需要制作频道final

于 2012-04-09T06:49:38.650 回答
1

尝试关注

 if (item == (_publicChannels.size())) {
            System.out.println("NEW CHANNEL");
            CreateNewChannel();
            dialog.dismiss();
        }else{
            String channel = channels[item];
            System.out.println("Selected: " + channel);
        }
于 2012-04-09T06:49:46.887 回答
0

退出时的示例 CONFIRMATION 对话框

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Are you sure you want to exit?")
                .setCancelable(false)
                .setPositiveButton("Yes",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                finish();
                            }
                        })
                .setNegativeButton("No",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                dialog.cancel();
                            }
                        });
        AlertDialog alert = builder.create();
        alert.show();
于 2012-04-09T07:29:46.577 回答