我有一個單選按鈕的自定義對話框,我需要從打開的對話框中聽取更改(如有),並從中設置文本。由於我已經完成了使用java,我不知道如何使用onCheckedChangedListener。我怎麼做 。我是新來的機器人,我不知道多少。請幫助我。自定義對話框的單選按鈕
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;
}
}
你也可以看看這個 http://stackoverflow.com/questions/12908902/custom-dialog-date-and-time-picker-with-radio-buttons – chitranna