来自AlertDialog的Activity中的Android SetText

时间:2015-09-29 22:46:46

标签: android dialog alertdialog settext

我的TextView上有一个mainActivity,我按如下方式创建AlertDialog

    textViewPropanol = (TextView) findViewById(R.id.textViewPropranol);
    boton_propanol = (ToggleButton) findViewById(R.id.button_propanol);
    boton_propanol.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(boton_propanol.isChecked()) {
                textViewPropanol.setText("activacted");
                final AlertDialog.Builder a_builder = new AlertDialog.Builder(MedicamentosActivity.this);
                a_builder.setCancelable(false)
                        .setItems(R.array.mediPropanolol, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                textViewPropanol.setText();

                            }
                        })
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        }) ;
                AlertDialog alert = a_builder.create();
                alert.setTitle("Medicina");
                alert.show();
            }
            else{
                textViewPropanol.setText("des");}
        }
    });

我想使用从textViewPropanol中选择的选项在AlertDialog中设置文字。

1 个答案:

答案 0 :(得分:0)

String array[] = new String[]{};
boton_propanol.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(boton_propanol.isChecked()) {
                array = getResources().getStringArray(R.array.mediPropanolol);
                textViewPropanol.setText("activacted");
                final AlertDialog.Builder a_builder = new AlertDialog.Builder(MedicamentosActivity.this);
                a_builder.setCancelable(false)
                        .setItems(R.array.mediPropanolol, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                textViewPropanol.setText(array[which]);

                            }
                        })
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        }) ;
                AlertDialog alert = a_builder.create();
                alert.setTitle("Medicina");
                alert.show();
            }
            else{
                textViewPropanol.setText("des");}
        }
    });