私AlertDialog
には が含まれていListView
ます。が閉じAlertDialog
られ、戻ってくると、ListView
が 2 回表示されます。なぜこれが起こるのかわかりません。これが私のコードです:
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.