我尝试使用ArrayAdapter进行自定义单选对话框。首先,我创建了一个带有匿名类的数组适配器。
private final Dialog createListFile(final String[] fileList) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.compare);
ArrayAdapter<String> dialogArrayAdapter = new ArrayAdapter<String>(this, R.layout.dialog_row, fileList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderDialog holder = null;
if (convertView == null) {are
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.dialog_row, null);
holder = new ViewHolderDialog();
holder.date = (TextView) convertView.findViewById(R.id.dialogDate);
holder.days = (TextView) convertView.findViewById(R.id.dialogDays);
convertView.setTag(holder);
} else {
holder = (ViewHolderDialog) convertView.getTag();
}
String item = getItem(position);
holder.date.setText(item);
holder.days.setText("giorni");
return convertView;
}
};
然后我调用构建器的setSingleChoiceItems方法来创建一个带有复选标记的项目列表;传递为先前创建的第一个参数arrayAdapter。
builder.setSingleChoiceItems(dialogArrayAdapter, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
n = whichButton;
}
});
问题是当我运行代码时显示复选标记。我在哪里做错了?
答案 0 :(得分:-1)
builder.setSingleChoiceItems
会自动添加广播组检查标记。如果您不需要,请使用builder.setItems。请参阅:http://developer.android.com/guide/topics/ui/dialogs.html
查看代码和android开发人员和。使用builder.setItems
时,如果不使用ArrayAdapter
,您将会提高效果。