我有一个带有单选按钮的自定义对话框,我需要从打开的对话框中监听更改(如果有的话)并从中设置文本。由于我使用 java 完成了该操作,因此我不知道如何使用 onCheckedChangedListener。我怎么做 。我是android新手,我不太了解。请帮助我。
public class Availability extends Activity implements OnClickListener {
ToggleButton override;
TextView status;
Button Overridestatus;
CharSequence [] choice = {"RemoteOffice","Office","Personel mobile","Home","Mobile","Temporary","Do not Disturb","Working Remotely","Non work day","Work Day"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.availability);
override = (ToggleButton) findViewById(R.id.tbOver);
override.setOnClickListener(this);
status = (TextView) findViewById(R.id.tvstatus);
Overridestatus = (Button) findViewById(R.id.bstatus);
Overridestatus.setOnClickListener(this);
}
public void onClick(View view) {
// TODO Auto-generated method stub
switch (view.getId()) {
case R.id.tbOver:
if (override.isChecked()) {
status.setText("Override");
Overridestatus.setText("Personal Mobile");
} else {
status.setText("Currently");
Overridestatus.setText("Use Schedule - Do Not Disturb");
}
break;
case R.id.bstatus:
{
if (override.isChecked()){
showDialog(0);
}
}
break;
}
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch (id) {
case 0:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select System Server");
builder.setIcon(R.drawable.ic_btn_round_more_normal);
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// TODO Auto-generated method stub
Intent menu = new Intent(Availability.this,MenuScreen.class);
startActivity(menu);
}
});
builder.setNegativeButton("CANCEL",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.setSingleChoiceItems(choice, -1,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// TODO Auto-generated method stub
}
});
builder.create();
builder.show();
}
return null;
}
}