2010-07-09 8 views
0

Je développe une application pour Android dans Eclipse. Actuellement, je cible le niveau 3 de l'API, mais j'ai effectué un test par erreur sur un émulateur Android 1.6 (niveau 4 de l'API). Sur 1.6 cela a fonctionné très bien, mais sur 1.5 mon ListView avec CHOICE_MODE_SINGLE ne sélectionne pas les articles quand ils sont cliqués dessus.ListView ne vérifie pas les éléments sur Android 1.5

Voici mon XML listview:

<ListView 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    android:id="@+id/ListDomains" 
    android:layout_margin="5px" 
    android:choiceMode="singleChoice" 
    android:clickable="false" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:descendantFocusability="beforeDescendants" 
> 
</ListView> 

Voici le XML pour les éléments de la listview:

<?xml version="1.0" encoding="utf-8"?> 
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:id="@+id/domain_list_value" 
    android:checkMark="?android:attr/listChoiceIndicatorSingle" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_width="fill_parent" 
> 
</CheckedTextView> 

J'ai créé un adaptateur ArrayList personnalisé pour me laisser personnaliser getView. Voici le code pour DomainArrayAdapter:

public class DomainArrayAdapter extends ArrayAdapter<char[]> { 

    private LayoutInflater mInflater; 

    public DomainArrayAdapter(Context context, int textViewResourceId, 
      List<char[]> objects) {  
     super(context, textViewResourceId, objects);  
     mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     if(convertView == null){ 
      convertView = mInflater.inflate(R.layout.domain_list, null); 
     } 

     char[] text = super.getItem(position); 

     ((CheckedTextView)convertView).setText(text, 0, text.length); 
     return convertView; 
    } 

} 

Tout ce code fonctionne très bien compilé niveau de l'API 3 et exécuter sur un émulateur Android 1.6. Toutefois, exécuté sur un émulateur 1.5, les éléments de ListView ne vérifient pas lorsque vous cliquez dessus.

Des idées?

Répondre

1

Il semble qu'Android 1.5 ne respecte pas le paramètre choiceMode défini dans la liste XML. Un réglage provoque programatically qu'il fonctionne correctement:

ListView listDomains = (ListView) findViewById(R.id.ListDomains); 

    Log.d("app", String.valueOf(listDomains.getChoiceMode())); //prints 0 

    listDomains.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

    Log.d("app", String.valueOf(listDomains.getChoiceMode())); //prints 1 

Quelqu'un at-il vu d'autre ce genre de comportement?

Questions connexes