我想在自定义对话框中实现 setSingleChoiceItems 但无法做到。我希望当我按下一个按钮时会弹出一个带有 setSingleChoiceItems 的自定义警报框,然后它将转到另一个活动。
下面的代码:
package com.ssaa;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class VoteActivity extends Activity {
/** Called when the activity is first created. */
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button) findViewById(R.id.vote);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(1);
}
});
}
public void showallDialog()
{
final CharSequence[] items = {"Yes", "No", "Can't Say"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("AM I AWESOME?");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item)
{
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
Dialog d =null;
switch (id) {
case 1:
showallDialog();
default:
break;
}
return d;
}
/* class MyCustomDialogue extends Dialog
{
public MyCustomDialogue(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
}*/
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
我认为我在方法上做错了showallDialog()
。请帮我纠正它。