this may give you some idea...
private void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
ArrayList<String> arrayList = new ArrayList<String>();
ArrayList<Boolean> selectedList = new ArrayList<Boolean>();
for (int i = 1; i <= 20; i++) {
arrayList.add("" + i);
selectedList.add(i % 2 == 0);
}
builder.setAdapter(new MyAdapter(arrayList, selectedList), null);
builder.show();
}
public static class MyAdapter extends BaseAdapter {
private ArrayList<String> arrayList;
private ArrayList<Boolean> selectedList;
public MyAdapter(ArrayList<String> arrayList,
ArrayList<Boolean> selectedList) {
this.arrayList = arrayList;
this.selectedList = selectedList;
}
@Override
public int getCount() {
return arrayList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getView(parent.getContext(), position);
}
private RelativeLayout getView(Context context, int position) {
RelativeLayout relativeLayout = new RelativeLayout(context);
AbsListView.LayoutParams params = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
relativeLayout.setLayoutParams(params);
TextView textView = new TextView(context);
textView.setText(arrayList.get(position));
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
layoutParams.leftMargin = 30;
textView.setLayoutParams(layoutParams);
relativeLayout.addView(textView);
CheckBox checkBox = new CheckBox(context);
layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layoutParams.rightMargin = 30;
checkBox.setLayoutParams(layoutParams);
checkBox.setClickable(false);
if (selectedList != null) {
checkBox.setChecked(selectedList.get(position));
}
relativeLayout.addView(checkBox);
return relativeLayout;
}
}