2011-05-19 3 views
1

J'ai une liste d'images chargées dans un AlertDialog en utilisant un ArrayAdapter personnalisé et j'utilise AlertDialog builder.setSingleChoiceItems mais il n'affiche pas les boutons Radio. Voici une partie de mon code:Les boutons radio ne sont pas affichés lors de l'utilisation de AlertDialog avec un adaptateur personnalisé

final ListAdapter adapter = new IconAdapter(AddNote.this, R.layout.list_image_item); 

    btnPickIcon.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(AddNote.this); 
      builder.setTitle("Pick an icon"); 
      builder.setSingleChoiceItems(adapter, 0, new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int item) 
       { 
        Toast.makeText(AddNote.this, "You selected " + item,Toast.LENGTH_LONG).show(); 
        dialog.dismiss(); 
       } 
      }); 
      AlertDialog alert = builder.create(); 
      alert.show(); 
     } 
    }); 

Et l'adaptateur:

class ViewHolder { 
    ImageView icon; 
} 

public class IconAdapter extends ArrayAdapter<Integer> { 
//  ArrayList<View> imageViews = new ArrayList<View>(); 
    private Integer[] mIconList = { 
       R.drawable.symbol1, R.drawable.symbol2, R.drawable.symbol3, R.drawable.symbol4, R.drawable.symbol5}; 

    public IconAdapter(Context context, int textViewResourceId) { 
     super(context, textViewResourceId); 
    } 

     ViewHolder holder; 

     public int getCount() { 
     return mIconList.length; 
    } 

    public Integer getItem(int position) { 
     return mIconList[position]; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

     public View getView(int position, View convertView, ViewGroup parent) { 
       final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

       if (convertView == null) { 
         convertView = inflater.inflate(R.layout.list_image_item, null); 

         holder = new ViewHolder(); 
         holder.icon = (ImageView) convertView.findViewById(R.id.listImage); 
         convertView.setTag(holder); 
       } else { 
         holder = (ViewHolder) convertView.getTag(); 
       }    

        Drawable tile = getResources().getDrawable(mIconList[position]); 
        holder.icon.setImageDrawable(tile); 
       return convertView; 
     } 
    } 

Quelqu'un sait pourquoi les boutons radio n'apparaissent pas?

+0

Toujours aux prises avec l'affichage des boutons radio. Quelqu'un d'autre a-t-il vu quelque chose comme ça? – Millec8

Répondre

0
final ListAdapter adapter = new IconAdapter(AddNote.this, R.layout.simple_list_item_single_choice); 

Utilisez simple_list_item_single_choice au lieu de list_image_item.

Questions connexes