我的AlertDialog
包含一个ListView
. 当AlertDialog
被解雇时,它又回来了ListView
被呈现两次。我不知道为什么会这样。这是我的代码:
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(LegendTest.this);
final LayoutInflater inflater = (LayoutInflater) Legend`enter code here`Test.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.selectfeaturetype, null);
ListView listView = (ListView) view.findViewById(R.id.listView1);
Dialog dialog;
switch (id) {
case LEGEND_DIALOG:
builder.setTitle("Set legend");
builder.setView(view);
listView.setAdapter(new BaseAdapter() {
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
if(convertView == null)
{
convertView = inflater.inflate(R.layout.itemwithimage, null);
}
MyLegend legendItem = data.get(position);
if(legendItem != null)
{
ImageView img = (ImageView) convertView.findViewById(R.id.listimageView);
img.setImageBitmap(legendItem.legendImage);
TextView txt = (TextView) convertView.findViewById(R.id.listtextView);
txt.setText(legendItem.legendname);
}
return convertView;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public int getCount() {
if (data == null)
return 0;
return data.size();
}
});
dialog = builder.create();
break;
default:
dialog = null;
break;
}
return dialog.