Problem with android single choice dialog using arrayAdapter
I tried to do a custom single choice dialog using an ArrayAdapter. First i created a Array Adapter with anonymous class.
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;
}
};
Then i called the setSingleChoiceItems method of the builder to create a list of items with a check mark displayed; passing as the first parameter arrayAdapter created earlier.
builder.setSingleChoiceItems(dialogArrayAdapter, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
n = whichButton;
}
});
The problem is that when I run the code shows the check mark. Where am I doing wrong?
builder.setSingleChoiceItems
adds radio group check marks automatically. If you do not need this, then use builder.setItems. See: http://developer.android.com/guide/topics/ui/dialogs.html
Look at the code and android developer and. Using builder.setItems
do you will improve the performance when not use a ArrayAdapter
.
精彩评论