我的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
中设置文字。
答案 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");}
}
});