2012-02-28 5 views
0

ちょっと私はヘルプアクティビティを設計しました。それぞれの特定の子を持つ種類の親(groupItems)を持っています。これまでのところ問題はありません。しかし、ExpandableListViewのchildItemsはデフォルトでクリック可能であるため、クリックすると点滅します。そして、それは私が避けたいものです!これは私がここでチャイルズExpandableListActivity childItems unclickableにする

<?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> 

に使用するレイアウトは、私のソースコードは(これは動作します)コンテンツで満たされますようどのようにすべてです:

私がやりたいものを
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; 
} 

}

textview属性を子孫がunclickableにすることです:私は既にtextview属性を試しましたが、誰も効果がありませんでした。

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

アイデアを持っているかもしれない人に事前に感謝!

答えて

1

SimpleExpandableListAdapterを拡張するなど、独自のExpandableListAdapterをカスタマイズし、.newChildView()および.getChildView()メソッドをオーバーライドする必要があります。これらのオーバーライドされたメソッドでは、子ビューのOnClickListenerとOnLongClickListenerの両方を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; 
} 

Aビューのクリッカブルプロパティは、それが状態がクリックされたとき、それはビューがクリックされ得ることができるかどうかで役割を果たしていない「押し」に変更されますだか否かを判定する。これを試してみてください

+0

グレート、私はすでにそれはcouldnと思いましたそれほど難しくはありません。ちょうどそれを試した - 完璧な作品。どうもありがとうございました。 – Vossi

1

など、ExpandableListAdapterはそのグループと子ビューにデフォルトのリスナーを設定しますので、あなたがクリックする任意の「反応」を削除するには、それらを削除する必要があり、焦点:

getExpandableListView().setOnChildClickListener(null); 
+0

あなたのソリューションもチェックしましたが、うまくいかない - とにかくあなたの返事に感謝します。 – Vossi

関連する問題