2012-02-28 3 views
0

Hey, j'ai conçu une activité d'aide et j'ai des parents (groupes) qui ont chacun un enfant spécifique. Jusqu'à présent, il n'y a pas de problème. Mais les éléments childItems de ExpandableListView sont cliquables par défaut, de sorte qu'ils clignotent si vous cliquez dessus. Et c'est exactement ce que je veux éviter! Ceci est la mise en page que j'utilise pour les ChildsExpandableListActivity make childItems non cliquable

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <TextView android:id="@+id/grp_child" 
     android:paddingLeft="20dp" 
     android:textSize="15dp" 
     android:textStyle="normal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

Voici mon code source comment tout cela se remplit de contenu (cela fonctionne):

public class HelpActivity extends ExpandableListActivity { 
private static final String TAG = "HelpActivity"; 

private static final String PARENT = "parent"; 
private static final String CHILD = "child"; 

private List<HashMap<String,String>> parents; 
private List<List<HashMap<String, String>>> childs; 

public void onCreate(Bundle savedInstanceState) { 
    Log.i(TAG, "Instantiated new " + this.getClass()); 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.help); 
    parents = createParentList(); 
    childs = createChildList(); 
    SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
     this, 
     parents,      // Describing data of group List 
     R.layout.help_group_item,  // Group item layout XML. 
     new String[] {PARENT},   // the key of group item. 
     new int[] {R.id.row_name},  // ID of each group item.-Data under the key goes into this TextView. 
     childs,       // childData describes second-level entries. 
     R.layout.help_child_item,  // Layout for sub-level entries(second level). 
     new String[] {CHILD},   // Keys in childData maps to display. 
     new int[] {R.id.grp_child}  // Data under the keys above go into these TextViews. 
    ); 
    setListAdapter(expListAdapter);  // setting the adapter in the list. 
} 

/* Creating the Hashmap for the row */ 
private List<HashMap<String,String>> createParentList() { 
    ArrayList<HashMap<String,String>> result = new ArrayList<HashMap<String,String>>(); 
    HashMap<String,String> m = new HashMap<String,String>(); 
    m.put(PARENT,getResources().getString(R.string.help_parent_1)); 
    result.add(m); 
    m = new HashMap<String,String>(); 
    m.put(PARENT,getResources().getString(R.string.help_parent_2)); 
    result.add(m); 
    m = new HashMap<String,String>(); 
    m.put(PARENT,getResources().getString(R.string.help_parent_3)); 
    result.add(m); 
    return result; 
} 

/* creatin the HashMap for the children */ 
private List<List<HashMap<String, String>>> createChildList() { 
    ArrayList<List<HashMap<String, String>>> result = new ArrayList<List<HashMap<String, String>>>(); 
    for (int i=0;i<parents.size();i++){ 
     HashMap<String, String> sec = parents.get(i); 
     ArrayList<HashMap<String, String>> secChild = new ArrayList<HashMap<String, String>>(); 
     HashMap<String,String> child = new HashMap<String,String>(); 
     if(sec.containsValue(getResources().getString(R.string.help_parent_1))){ 
      child.put(CHILD, getResources().getString(R.string.help_child_1)); 
     }else if(sec.containsValue(getResources().getString(R.string.help_parent_2))){ 
      child.put(CHILD, getResources().getString(R.string.help_child_2)); 
     }else if(sec.containsValue(getResources().getString(R.string.help_parent_3))){ 
      child.put(CHILD, getResources().getString(R.string.help_child_3)); 
     }else if(sec.containsValue(getResources().getString(R.string.help_parent_4))){ 
      child.put(CHILD, getResources().getString(R.string.help_child_4)); 
     } 
     secChild.add(child); 
     result.add(secChild); 
    } 
    return result; 
} 

}

ce que je veux faire est de rendre le texte invisible pour l'enfant: J'ai déjà essayé les attributs de textview mais personne n'a eu d'effet

android:clickable="false" 
android:focusable="false" 
android:enabled="false" 

Merci d'avance à tous ceux qui pourraient avoir une idée!

Répondre

1

Vous devez personnaliser votre propre ExpandableListAdapter, par exemple en développant SimpleExpandableListAdapter et remplacer les méthodes .newChildView() et .getChildView(). Dans ces méthodes substituées, vous personnalisez en définissant OnClickListener et OnLongClickListener de la vue enfant tous les deux à null.

@Override 
public View newChildView(boolean isLastChild, ViewGroup parent) { 
    View v = super.newChildView(isLastChild, parent); 
    v.setOnClickListener(null); 
    v.setOnLongClickListener(null); 
    return v; 
} 

@Override 
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent); 
    v.setOnClickListener(null); 
    v.setOnLongClickListener(null); 
    return v; 
} 

propriété cliquable d'une vue détermine uniquement si elle est ou non l'état passe à « pressé » quand on clique dessus, il ne joue pas un rôle dans si la vue peut obtenir cliqué ou non. Un ExpandableListAdapter fixe Listeners par défaut à ses constatations de groupe et de l'enfant, vous devez les supprimer pour éliminer toute « réaction » aux clics, mise au point, etc.

+0

Grand, je l'ai déjà pensé qu'il couldn ne sois pas si difficile. Juste essayé - fonctionne parfait. Merci beaucoup. – Vossi

1

Essayez ceci:

getExpandableListView().setOnChildClickListener(null); 
+0

J'ai aussi vérifié votre solution mais cela ne fonctionne pas - de toute façon merci pour votre réponse. – Vossi